"The given path's format is not supported."

All Blond picture All Blond · Sep 8, 2011 · Viewed 292.1k times · Source

I have the following code in my web service:

string str_uploadpath = Server.MapPath("/UploadBucket/Raw/");
FileStream objfilestream = new FileStream(str_uploadpath +
                fileName, FileMode.Create, FileAccess.ReadWrite);

Can someone help me resolve the issue with this error message from line 2 of the code.

The given path's format is not supported.

Permission on the folder is set to full access to everyone and it is the actual path to the folder.

The breakpoint gave me the value of str_uploadpath as C:\\webprojects\\webservices\\UploadBucket\\Raw\\.

What is wrong with this string?

Answer

user586399 picture user586399 · Sep 8, 2011

Rather than using str_uploadpath + fileName, try using System.IO.Path.Combine instead:

Path.Combine(str_uploadpath, fileName);

which returns a string.