local file download

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);
 
S

Steve C. Orr, MCSD

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")
;
 
D

dsoltesz

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

dsoltesz

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


.
 
K

Kevin Spencer

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.
 
K

Kevin Spencer

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);
.
 

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,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top