Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > How to force download ?

Reply
Thread Tools

How to force download ?

 
 
fredda054@gmail.com
Guest
Posts: n/a
 
      05-23-2006
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();
}

}

 
Reply With Quote
 
 
 
 
Mike Brind
Guest
Posts: n/a
 
      05-23-2006

http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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)


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

--
Mike Brind

 
Reply With Quote
 
 
 
 
fredda054@gmail.com
Guest
Posts: n/a
 
      05-24-2006
Ooops, sorry, my misstake. I've used this group alot before, but kind
of forgot that it's all about classic ASP.



(E-Mail Removed) skrev:

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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Nike air force one, air force 1, air force one low cut, air force one abdul_razak@indiatimes.com Digital Photography 2 12-31-2008 04:29 PM
Nike Air Force Ones,Air Force One Air Force One-1 lky52193@gmail.com Computer Support 0 01-17-2008 04:40 PM
Nike Air Force Ones,Air Force One Air Force One-1,25th anniversary lky52112@gmail.com Digital Photography 0 01-15-2008 04:46 PM
Nike Air Force Ones,Air Force One Air Force One-1,25th anniversary lky52112@gmail.com Digital Photography 0 01-15-2008 04:34 PM



Advertisments