Dynamically sending files to a user

  • Thread starter Thread starter BoltonWolf
  • Start date Start date
B

BoltonWolf

Hi,

I have an ASP.Net app which displays data from a spreedsheet. This
spread sheet is located outside of the virtual directories.

I want to be able to give the user the option to download the
spreadsheet, without having to move it into the virtual directory.

Does anyone know how I can achive this?

Is there away I can grab the file and fire it to the users browser?

Many thanks in advance

Chris
 
I have an ASP.Net app which displays data from a spreedsheet. This
spread sheet is located outside of the virtual directories.

I want to be able to give the user the option to download the
spreadsheet, without having to move it into the virtual directory.

Does anyone know how I can achive this?
You can use the HttpResonse.WriteFile method to write the file to the
reponse stream. Here is a simple example:

FileInfo myFileInfo=new FileInfo("MySpreedsheet.xls");
Response.WriteFile(myFileInfo.FullName,0,myFileInfo.Length);

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
 
Thanks Anders, I've tried that and it seems to write the actual
contents of the file to the Browser.

I am trying to give the user the option to download the file, so would
need it to pop up a Save, Open type dialogue.

TIA

Chris
 
BoltonWolf said:
I am trying to give the user the option to download the file, so would
need it to pop up a Save, Open type dialogue.
Just provide a link to a page that uses HttpResponse.WrtieFile. You
should also add a "content-disposition" header with its value set to
"attachment; filename=myfile.xls" where myfile.xls is the actual name of
your Excel spreedsheet file to ensure that a file download dialog is
shown to the user.
The following code adds a "content-disposition" header:
Response.AddHeader("content-disposition",string.Format("attachment;
filename={0}",myFilename));

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
 
Back
Top