开发者

get file type of request.files in asp.net

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜