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
.
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 '.
using FileStream fs = File. OpenRead(fileName); With File. OpenRead we open a file for reading.
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.
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.
string extension = Path.GetExtension(myFileStream.Name);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With