Reputation: 181
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?
Upvotes: 1
Views: 104
Reputation: 4903
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;
Upvotes: 2
Reputation: 2714
Your variable newFile
is never given a value, so Path.Combine() is going to fail.
Upvotes: 0