开发者

get file type of request.files in asp.net

开发者 https://www.devze.com 2023-02-13 08:29 出处:网络
How to get file extension from the request.files开发者_JAVA技巧 collection in asp.net?I think this should do the trick:

How to get file extension from the request.files开发者_JAVA技巧 collection in asp.net?


I think this should do the trick:

foreach (HttpPostedFile file in Request.Files) {
    string extension = System.IO.Path.GetExtension(file.FileName);
}


Each HttpPostedFile in Request.Files has a FileName that includes the extension; to get just the extension, use Path.GetExtension(file.FileName)

Note that using the content-type may be more reliable in many cases.


Request.Files is actually a Name Object Collection so this code would work better

foreach (string keyName in Request.Files) {
    string extension = System.IO.Path.GetExtension(Request.Files[keyName].FileName);
}

and this code worked for me.

0

精彩评论

暂无评论...
验证码 换一张
取 消