C# .NET - The given path's format is not supported.

Asked By SVK N on 04-Oct-11 06:59 AM
using
 filename =FileUpload1.PostedFile.FileName;

 
  FileUpload1.SaveAs(Server.MapPath("/upload/") + filename);

the code works fine in  my development machine but when i deploy the code to another server  i get error

http://www.dotnetnuke.com/Resources/Forums/forumid/107/postid/203442/scope/posts.aspx#203442 

i checked many forums & done but still same issue
Cosmos Mysore replied to SVK N on 04-Oct-11 07:08 AM

You can try using the configuration file

<appSettings>

<add key="FileDirectory" value="C:\upload\"/>

</appSettings>

string directory = ConfigurationManager.AppSettings["FileDirectory"].Trim()


FileUpload1.SaveAs(directory + filename);

FileUpload1.SaveAs(+ filename);

Cosmos Mysore replied to Cosmos Mysore on 04-Oct-11 07:09 AM
You can try using the configuration file

<appSettings>

<add key="FileDirectory" value="C:\upload\"/>


</appSettings>

string directory = ConfigurationManager.AppSettings["FileDirectory"].Trim()

FileUpload1.SaveAs(directory + filename);

dipa ahuja replied to SVK N on 04-Oct-11 07:27 AM
Do you have taken update panel for fileUpload?
Reena Jain replied to SVK N on 04-Oct-11 07:37 AM
Hi,

To resolve the error use this line of code
string filename = Path.GetFileName(FileUploadControl.FileName);
FileUploadControl.SaveAs(Server.MapPath("~/upload") + filename);

Instead of this
 filename =FileUpload1.PostedFile.FileName;
    FileUpload1.SaveAs(Server.MapPath("/upload/") + filename);

in mappath use upload as a folder to map
SVK N replied to Reena Jain on 04-Oct-11 07:53 AM
Could not find a part of the path 'c:\inetpub\wwwroot\upload\filterdes.xlsx'.
getting this error
Cosmos Mysore replied to SVK N on 04-Oct-11 08:15 AM

'c:\inetpub\wwwroot\upload\filterdes.xlsx'

in this your missing Website Name

FileUploadControl.SaveAs(Server.MapPath("~[WebsiteName]/upload") + filename);

Reena Jain replied to SVK N on 04-Oct-11 09:37 AM
Hi,

Request.ApplicationPath will return a virtual path string like "/WebApplication1". However, StreamReader require a physical path like "C:\inetpub\webapplication1\filterdes.xlsx". To convert a virtual path to physical path, we can use MapPath method:

MyFile =Server.MapPath(Request.ApplicationPath + "//filterdes.xlsx");

As i am checking there is no project in wwwroot on server according to path. Have you tried searching your project (configuration files included) for that path? It will be surely written somewhere, you just need to find it