获取该文件的扩展名在FileUpload控件 [英] Getting extension of the file in FileUpload Control

查看:127
本文介绍了获取该文件的扩展名在FileUpload控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


此刻我得到的文件的文件扩展名,如:

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

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

但是,如果用户更改文件的文件扩展名(例如,用户可以重命名test.txt的test.jpg放在),我不能让真正的扩展。有什么解决办法?

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 ?

推荐答案

您似乎在询问是否可以从它的内容识别文件类型。

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.

如果你只担心文字VS二进制,见<一href=\"http://stackoverflow.com/questions/277521/how-to-identify-the-file-content-is-in-ascii-or-binary\">this SO问题和答案。

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

请参阅this SO回答,用于检查文件是JPG - 这种方法可以扩展到使用其他文件标题,如在这个答案的前两个环节。

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.

这篇关于获取该文件的扩展名在FileUpload控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆