简体   繁体   中英

Error The given path's format is not supported

I had this error when use upload file control " The given path's format is not supported " .

if (FUFile.PostedFile.ContentLength != 0)
        {
            string tempVar = "~/res/Posts/" + FUFile.Value.ToString();
            FUFile.PostedFile.SaveAs(Server.MapPath(tempVar));

           ftier.Addpostfromfront(LoggedUserID, "4", txpost.Value, tempVar,  DateTime.Now, DateTime.Now, false, false);



        }

when I checked the code I had :

在此处输入图片说明

Use the property FileName after extracting just the filename

    if (FUFile.PostedFile.ContentLength != 0)
    {
        string file = Path.GetFileName(FUFile.PostedFile.FileName);
        string tempVar = Path.Combine("~/res/Posts/", file);
        FUFile.PostedFile.SaveAs(Server.MapPath(tempVar));
       ftier.Addpostfromfront(LoggedUserID, "4", txpost.Value, tempVar,  DateTime.Now, DateTime.Now, false, false);
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM