0

I'm trying to save a file on the server and I keep getting:

The SaveAs method is configured to require a rooted path, and the path '~\ImportFolder\chrome.dll' is not rooted.

However I created the folder in Visual Studio and it exist on the disk. What makes a path rooted?

HttpPostedFileBase file = Request.Files[i];
string path = Constants.importFolder;           
path = Path.Combine(path, file.FileName);
Server.MapPath(path);
file.SaveAs(path);
tereško
  • 56,151
  • 24
  • 92
  • 147
Mihai Bratulescu
  • 1,796
  • 3
  • 24
  • 43

1 Answers1

2

It .NET strings are immutable - once created they cannot be changed, so all methods that operates on strings return a new string.

In call:

Server.MapPath(path);

you are passing path to MapPath but you are ignoring return value of that method. Change the call to store result value in the same variable:

path = Server.MapPath(path);
Novakov
  • 2,995
  • 1
  • 18
  • 31