F
fredda054
Hi !
I have a problem with downloading csv files from a web app.
The files get created in the right directory, so I know they're there.
I get the error "The page cannot be found" when I click the download
link. Here's the code that does the work. (hopefully the format doesn't
get too screwed up here The code looks pretty straight forward, but
I can't understand what's wrong with it. It should download the file,
if it's there...
Greatfull for any help !
Fredrik
--------------------------------------------------------------------------------------------------------------------------------
public static void WriteFile(byte[] fileArr, string fileName)
{
RemoveFiles();
string path = HttpContext.Current.Server.MapPath("/Reports/" +
fileName);
//Create a filestream to send to the user
FileStream fStream = new FileStream(path, FileMode.Create,
FileAccess.Write);
try
{
Log.Message(EventCategory.Web, "Writing to user : " + path);
fStream.Write(fileArr, 0, fileArr.Length);
}
catch (Exception ex)
{
CpLog.Exception(EventCategory.Web, ex);
}
finally
{
fStream.Close();
}
}
public static void UploadFile(string fileName)
{
try
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AppendHeader("Content-Disposition",
"attachment; filename=" + fileName);
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Private);
string filePath =
ConfigurationSettings.AppSettings["ReportPath"].ToString();
Log.Message(EventCategory.Web, "Writing file to : " + filePath);
Log.Message(EventCategory.Web, "HttpHeader : " +
HttpContext.Current.Request.Headers.ToString());
HttpContext.Current.Response.Redirect(filePath + fileName);
}
catch(Exception ex)
{
Log.Exception(EventCategory.Web, ex);
}
finally
{
HttpContext.Current.Response.End();
}
}
I have a problem with downloading csv files from a web app.
The files get created in the right directory, so I know they're there.
I get the error "The page cannot be found" when I click the download
link. Here's the code that does the work. (hopefully the format doesn't
get too screwed up here The code looks pretty straight forward, but
I can't understand what's wrong with it. It should download the file,
if it's there...
Greatfull for any help !
Fredrik
--------------------------------------------------------------------------------------------------------------------------------
public static void WriteFile(byte[] fileArr, string fileName)
{
RemoveFiles();
string path = HttpContext.Current.Server.MapPath("/Reports/" +
fileName);
//Create a filestream to send to the user
FileStream fStream = new FileStream(path, FileMode.Create,
FileAccess.Write);
try
{
Log.Message(EventCategory.Web, "Writing to user : " + path);
fStream.Write(fileArr, 0, fileArr.Length);
}
catch (Exception ex)
{
CpLog.Exception(EventCategory.Web, ex);
}
finally
{
fStream.Close();
}
}
public static void UploadFile(string fileName)
{
try
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AppendHeader("Content-Disposition",
"attachment; filename=" + fileName);
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Private);
string filePath =
ConfigurationSettings.AppSettings["ReportPath"].ToString();
Log.Message(EventCategory.Web, "Writing file to : " + filePath);
Log.Message(EventCategory.Web, "HttpHeader : " +
HttpContext.Current.Request.Headers.ToString());
HttpContext.Current.Response.Redirect(filePath + fileName);
}
catch(Exception ex)
{
Log.Exception(EventCategory.Web, ex);
}
finally
{
HttpContext.Current.Response.End();
}
}