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

maz*_*ztt 47 asp.net-mvc file-extension

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

我想得到文件的扩展名来动态生成文件的名称.我将使用一种方法来分割类型.但我可以使用HttpPostedFileBase对象以干净的方式获得扩展吗?

SLa*_*aks 142

像这样:

string extension = Path.GetExtension(upload.FileName);
Run Code Online (Sandbox Code Playgroud)

这将包括领先..

请注意,您不应该认为扩展名是正确的.