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

ファイルの拡張子を取得して、ファイルの名前を動的に生成したいのですが、タイプを分割するために使用する1つの方法です。しかし、HttpPostedFileBaseオブジェクトを使用して、拡張機能をクリーンな方法で取得できますか?

4

1 に答える 1

178

このような:

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

これには、先​​頭が含まれます.

拡張子が正しいと思い込まないように注意してください。

于 2010-05-28T13:49:10.887 に答える