Getting the file extension in FileUpload Control

At the moment I am getting a file extension, for example:

string fileExt = System.IO.Path.GetExtension(filUpload.FileName);

But if the user changes the file extension of the file (for example, the user can rename "test.txt" to "test.jpg"), I cannot get the real extension. What's the solution?

+5
source share
3 answers

It seems you are asking if you can determine the type of file from its contents.

Most solutions will actually try to expand the file, but there are too many different types of files that can be reliably identifiable.

Most approaches use the first few bytes of a file to determine what they are.

, .

vs binary, . .

. this SO , JPG - , , .

+5

, , .

, , , .

. " ​​asp.net?

+1

Unable to get the "real" file extension - the file extension that you get from the file name is real. If the content of your content is a concern, you can get the content type using the .ContentType property and make sure that it is the type of content you expect - for example. image / jpg.

+1
source

All Articles