asp.net-mvc asp.net mvc HttpPostedFileBase 获取文件扩展名

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2929496/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 00:20:47  来源:igfitidea点击:

asp.net mvc HttpPostedFileBase getting file extension

asp.net-mvcfile-extension

提问by maztt

public string ContructOrganizationNameLogo(HttpPostedFileBase upload, string OrganizationName, int OrganizationID,string LangName)
    {
         var UploadedfileName = Path.GetFileName(upload.FileName);
        string type = upload.ContentType;
    }

I want to get the extension of the file to dynamically generate the name of the file.One way i will use to split the type. but can i use HttpPostedFileBase object to get the extension in the clean way?

我想获取文件的扩展名以动态生成文件的名称。我将使用一种方式来拆分类型。但是我可以使用 HttpPostedFileBase 对象以干净的方式获取扩展名吗?

回答by SLaks

Like this:

像这样:

string extension = Path.GetExtension(upload.FileName);

This will include a leading ..

这将包括一个领先的..

Note that the you should not assume that the extension is correct.

请注意,您不应假设扩展名是正确的。