Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determining file extension given a FileStream

Is there any way to know the type of the FileStream. I have a function that takes a FileStream object and I want to determine the file extension based on that FileStream.

like image 361
Abdul Samad Avatar asked Jan 18 '12 17:01

Abdul Samad


People also ask

How do I get the fileName extension?

If filename is empty or null, getExtension(String filename) will return the instance it was given. Otherwise, it returns extension of the filename. To do this it uses the method indexOfExtension(String) which, in turn, uses lastIndexof(char) to find the last occurrence of the '.

How do I view a FileStream file?

using FileStream fs = File. OpenRead(fileName); With File. OpenRead we open a file for reading.

How can I get file extension from Iformfile?

The object has a property HasFile which is then set to true. You can use ContentType Property of the PosteddFile object that gives you MIME type of the file and then you can determine the possible extension of the file. e.g. "application/excel" MIME would suggest it is an Excel file with . xls extension.

What is the use of FileStream?

Remarks. Use the FileStream class to read from, write to, open, and close files on a file system, and to manipulate other file-related operating system handles, including pipes, standard input, and standard output.


1 Answers

 string extension = Path.GetExtension(myFileStream.Name);
like image 121
Tomislav Markovski Avatar answered Sep 22 '22 15:09

Tomislav Markovski