Server.Mappath - Physical Path Given, Virtual Path Expected

Server.MapPath - Physical path given, virtual path expected

if you already know your folder is: E:\ftproot\sales then you do not need to use Server.MapPath, this last one is needed if you only have a relative virtual path like ~/folder/folder1 and you want to know the real path in the disk...

convert from physical path to virtual path

If you already have a physical path, it doesn't make sense to call Server.MapPath.

You're calling MapPath twice.

Asp.net: - is a physical path, but a virtual path was expected

Start by reading the doc: https://msdn.microsoft.com/en-us/library/ms524632(v=vs.90).aspx .

MapPath generates a physical path based on a releative or virtual path, so it makes no sense to give it a physical path. You already have the physical path so you should be able to completely skip that step.

protected void btnDownloadExcelTemp_Click(object sender, EventArgs e)
{
try
{
string strFileFormat = System.Configuration.ConfigurationManager.AppSettings["FormateFilePath"].ToString();
string strFilePath = strFileFormat + "/CMP_TEMPLATES.xlsx";
HttpResponse response = HttpContext.Current.Response;
response.Clear();
response.AppendHeader("content-disposition", "attachment; filename=" + "CMP_TEMPLATES.xlsx");
response.ContentType = "application/octet-stream";
response.WriteFile(strFilePath);
response.Flush();
response.End();
}
catch (Exception)
{
throw;
}
}

Error: Is a physical path, but a virtual path was expected

Try removing MapPath from your code, I think MapPath is used to locate the physical path to files in a virtual location. I'm currently on linux so I can't test this answer before giving it, but try something to the effect of:

using (StreamWriter myStream = new StreamWriter("~/path/tofolder/" + filename))
{
myStream.Write(stringWrite.ToString());
}

I'm guessing this is similar to the question at --> Server.MapPath - Physical path given, virtual path expected



Related Topics



Leave a reply



Submit