验证文件上载中的文件内容类型 [英] Validating content type of files in file upload
本文介绍了验证文件上载中的文件内容类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的网页上有一个文件上传控件。我想检查上传的文件类型是否仅为.wav格式。我尝试使用以下代码
HttpPostedFile objHPF = objHFC [ fldUpload];
string contentType = objHPF.ContentType.Split(' /')[ 1 ]。ToLower();
并检查是否contenttype =wav...
但是当我在两个浏览器(FF& Chrome)中上传相同的文件时,我在FF和WAV中获得了X-WAV chrome中的内容类型....那么我该怎么做才能检查内容类型以及发生这种情况的原因?请帮助..提前感谢
解决方案
您只需要 C#Path .GetExtension [ ^ ]
也见这个
检查上传文件的类型 [ ^ ]
问候..:)
还有一件事是你可以在ASP.NET中使用正则表达式验证控件来验证要上传的文件的扩展名。
请参阅此链接。
http:// www.c-sharpcorner.com/UploadFile/99bb20/validation-fo r-file-upload-control-in-Asp-Net / [ ^ ]
使用此链接可以更好地了解文件类型
http://stackoverflow.com/questions/15300567/alternative-to-findmimefromdata-method-in-urlmon-dll-one-which-has-more-mime-typ [ ^ ]
Hi,
In my web page there is a file upload control. I want to check whether the uploaded file type is of .wav format only. I tried with the following code
HttpPostedFile objHPF = objHFC["fldUpload"];
string contentType = objHPF.ContentType.Split('/')[1].ToLower();
and checked whether the contenttype="wav"...
But when i uploaded the same file in two browsers(FF & Chrome) i got X-WAV in FF and WAV as content type in chrome .... So what can i do to check the content type and why this happened? Pls help.. Thanks in advance
解决方案
All you need is C# Path.GetExtension[^]
See this also
Check type of uploaded file[^]
Regards..:)
One more thing is that you can use regular expression validation control in ASP.NET to validate the extension of the file to be uploaded.
Refer this link.
http://www.c-sharpcorner.com/UploadFile/99bb20/validation-for-file-upload-control-in-Asp-Net/[^]
Use this link to get better idea to the file type
http://stackoverflow.com/questions/15300567/alternative-to-findmimefromdata-method-in-urlmon-dll-one-which-has-more-mime-typ[^]
这篇关于验证文件上载中的文件内容类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文