How to force download ?

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();
}

}
 
M

Mike Brind

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

This newsgroup covers classic asp. DotNet is a different technology.
Try microsoft.public.dotnet.framework.aspnet.
 
F

fredda054

Ooops, sorry, my misstake. I've used this group alot before, but kind
of forgot that it's all about classic ASP.



(e-mail address removed) skrev:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top