local file download

  • Thread starter Thread starter dsoltesz
  • Start date Start date
D

dsoltesz

I'm trying to download a local file from the server.
Went I get the save dialog box and save the file, its
saving the current aspx page and not the file I
specified. Here is the code I"m using. Any ideas why
this is happening?

Response.ContentType = "application/x-zip-compressed";
System.IO.FileStream downloadFile = new
System.IO.FileStream
(@"C:\\VirtualCafeSourceSafeCode\\Database.zip",
System.IO.FileMode.Open);
long FileSize;
FileSize = downloadFile.Length;
byte[] getContent = new byte[(int)FileSize];
downloadFile.Read(getContent, 0, (int)
downloadFile.Length);
downloadFile.Close();
Response.BinaryWrite(getContent);
 
You just need to give it a real filename to use instead of the ASPX name.
You can do that with a line like this:
Response.AddHeader("Content-Disposition","attachment;filename=database.zip")
;
 
I need to add this line of code in to make it work.
Response.AddHeader("content-
disposition", "filename=Database.zip");
 
I didn't see your post till after...thanks for the reply
though
-----Original Message-----
You just need to give it a real filename to use instead of the ASPX name.
You can do that with a line like this:
Response.AddHeader("Content- Disposition","attachment;filename=database.zip")
;

--
I hope this helps,
Steve C. Orr, MCSD
http://Steve.Orr.net


dsoltesz said:
I'm trying to download a local file from the server.
Went I get the save dialog box and save the file, its
saving the current aspx page and not the file I
specified. Here is the code I"m using. Any ideas why
this is happening?

Response.ContentType = "application/x-zip-compressed";
System.IO.FileStream downloadFile = new
System.IO.FileStream
(@"C:\\VirtualCafeSourceSafeCode\\Database.zip",
System.IO.FileMode.Open);
long FileSize;
FileSize = downloadFile.Length;
byte[] getContent = new byte[(int)FileSize];
downloadFile.Read(getContent, 0, (int)
downloadFile.Length);
downloadFile.Close();
Response.BinaryWrite(getContent);


.
 
Are you sure it's saving an aspx page, or is it saving the zip file with the
same name as the aspx page? The second would be expected.

HTH,

Kevin Spencer
Microsoft FrontPage MVP
Internet Developer
http://www.takempis.com
Big things are made up of
lots of Little things.
 
That would do it.

HTH,

Kevin Spencer
Microsoft FrontPage MVP
Internet Developer
http://www.takempis.com
Big things are made up of
lots of Little things.

dsoltesz said:
I need to add this line of code in to make it work.
Response.AddHeader("content-
disposition", "filename=Database.zip");

-----Original Message-----
I'm trying to download a local file from the server.
Went I get the save dialog box and save the file, its
saving the current aspx page and not the file I
specified. Here is the code I"m using. Any ideas why
this is happening?

Response.ContentType = "application/x-zip-compressed";
System.IO.FileStream downloadFile = new
System.IO.FileStream
(@"C:\\VirtualCafeSourceSafeCode\\Database.zip",
System.IO.FileMode.Open);
long FileSize;
FileSize = downloadFile.Length;
byte[] getContent = new byte[(int)FileSize];
downloadFile.Read(getContent, 0, (int)
downloadFile.Length);
downloadFile.Close();
Response.BinaryWrite(getContent);
.
 
Back
Top