Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

At the moment i get file extension of the file like :

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
565 views
Welcome To Ask or Share your Answers For Others

1 Answer

You seem to be asking if you can identify file-type from its content.

Most solutions will indeed attempt the file extension, but there are too many different possible file types to be reliably identifiable.

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

Here is one list, here another.

If you are only worried about text vs binary, see this SO question and answers.

See this SO answer for checking if a file is a JPG - this approach can be extended to use other file headers as in the first two links in this answer.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...