Reputation: 11
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.".
Upvotes: 0
Views: 741
Reputation: 54378
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).
Upvotes: 1
Reputation: 13600
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.
Upvotes: 0