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
Questions About Entity Framework Context Lifetime
Why am I Getting Sehexception When Calling Roleenvironment.Getconfigurationsettingvalue("Mykey")
Formatting a C# String with Identical Spacing in Between Values
Should Idisposable.Dispose() Be Made Safe to Call Multiple Times
Programmatically Getting the Last Filled Excel Row Using C#
Remove Item in Dictionary Based on Value
C# Httpwebrequest the Underlying Connection Was Closed: an Unexpected Error Occurred on a Send
Convert String to Brushes/Brush Color Name in C#
Extracting Text from PDFs in C#
Create Http Post Request and Receive Response Using C# Console Application
How to Install a Windows Font Using C#
Reverse Sorted Dictionary in .Net
Publish a Project with Local Database
How to Get the Icon from the Executable File Only Having an Instance of It's Process in C#
Wpf: Cannot Reuse Window After It Has Been Closed
Ef Core 2.1 Hasconversion on All Properties of Type Datetime