0

I want to change Virtual Path(The path is out of project means local system or Server.) of the file Which is save on the folder in asp.net.

Code is

DataTable dtFiles =  
    GetFilesInDirectory(HttpContext.Current.Server.MapPath(UPLOADFOLDER));
gv.DataSource = dtFiles;
gv.DataBind();

if (dtFiles != null && dtFiles.Rows.Count > 0)
{
    double totalSize = Convert.ToDouble(dtFiles.Compute("SUM(Size)", ""));
    if (totalSize > 0) lblTotalSize.Text = CalculateFileSize(totalSize);
}

private static string UPLOADFOLDER = "D:/Uploads";

And the error show "D:/Uploads is not a valid virtual path.".

vyegorov
  • 20,303
  • 6
  • 57
  • 72
user1321614
  • 11
  • 1
  • 3

2 Answers2

1

If you want to get the files in a directory and you know the full path, then you don't need to use Server.MapPath(). Just use the path.

Incidentally, the path delimiter is incorrect in your code. The string "D:/Uploads" should be @"D:\Uploads" (note the leading @ sign to denote a string that should be treated literally and not escaped).

Community
  • 1
  • 1
Tim M.
  • 52,666
  • 12
  • 118
  • 157
0

Of course. You're telling your server to map path that is completely off the IIS. How is it supposed to do? If you're using a web application, try to avoid such ideas completely. Even though it is possible, it isn't a good idea because of security issues you can run into.

walther
  • 13,239
  • 5
  • 39
  • 64