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

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

4

1 回答 1

178

像这样:

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

这将包括一个领先的..

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

于 2010-05-28T13:49:10.887 回答