1

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?

1
  • Debug the application and put a breakpoint as the file is about to be saved. If you perform Path.Combine(storageLocation, newFile) in the Immediate window what is the output? Commented Aug 6, 2014 at 15:45

2 Answers 2

2

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;
Sign up to request clarification or add additional context in comments.

Comments

0

Your variable newFile is never given a value, so Path.Combine() is going to fail.

3 Comments

Why was this downvoted? With the information given, this is entirely accurate.
+1 - based on the snippet of code your answer is the probable cause.
newFile as value. I tried Response.Write(newFile) then I get the filename

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.