简体   繁体   中英

Asp.net file upload not working

I am trying to upload file but getting an error The given path's format is not supported."

    string storageLocation = string.Empty;
    string newFile;

    switch (ddlDocType.SelectedItem.Text)
    {
        case "Letter":
            storageLocation = Server.MapPath("~/Documents/Letters/");
            break;

...

        if (filePosted.ContentLength > 0)
        {
                filePosted.SaveAs(Path.Combine( storageLocation , newFile));
        }

and also tried the following but still not working.

filePosted.SaveAs( storageLocation ,+ newFile);

How can I solve the problem?

If newFile is a file name like newFile="myfile.rar"; then use this:

filePosted.SaveAs(storageLocation + newFile);

It seems you have an extra , near the + .

But if newFile is empty like the question's code, you should set a value before .SaveAs :

newFile = filePosted.FileName;

您的变量newFile永远不会被赋值,因此Path.Combine()将失败。

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