user1321614
user1321614

Reputation: 11

virtual path change

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

Answers (2)

Tim M.
Tim M.

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

walther
walther

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

Related Questions