Server Map Path save problems when using IE or Safari

1k views Asked by At

I have created an intranet application and am having some difficulties with IE and safari on windows when trying to use the following code to save a posted file to an internal folder within the MVC solution folder structure:

postedFile.SaveAs(HttpContext.Current.Server.MapPath("~/" + baseFolderName + "/" + contentFolder + "/" + fileName));

This works as expected when using Firefox and chrome so I am unsure as to why this is happening something to do with the format of the string.

System.NotSupportedException: The given path's format is not supported.

The name of the basefolder and contentfolder being passed are the same in the tests so I am assuming the problem lies with IE trying to find the path.

1

There are 1 answers

2
Jay On BEST ANSWER

IE was getting the FileName of the posted file with its location included. I resolved the issue by getting just the file extension with the following code:

System.IO.Path.GetFileName(image.FileName))