downloading file get empty from one server.

G

Guest

Hi,
On one of my server, downloading file by clicking a button give empt
file. On the other servers work perfectly. Is any idea ? What should be
change in IIS Metabase setting?
After click the button on an aspx page, IE prompts the users whether they
want to open, save or cancel the download with correct name. No matter click
open or save, it started download and transfered 0 byte. I checked the server
side it did created the file with correct contents. The code is same as those
many posted here.
Thanks in advance.
Frank
 
G

Guest

Code runs good on other servers. But here is the code:

Response.AddHeader("Content-Type", "application/csv")
Response.AddHeader("Content-Disposition",
"attachment;filename=" + fileName + ";")

Dim Fs As FileStream = New FileStream(Server.MapPath("~/" &
fileName), FileMode.Open)
Dim FileSize As Long = Fs.Length
Dim bBuffer() As Byte = New Byte(FileSize) {}
Fs.Read(bBuffer, 0, Convert.ToInt32(FileSize))
Fs.Close()

Response.BinaryWrite(bBuffer)
Response.Flush()
Response.Close()

Thanks,
Frank
 
G

Guest

Maybe here is not the correct place to post this question. Any suggestion
that which newsgroup I should put ?
Thanks
 
A

agapeton

I feel kinda weird about the combination of csv and binary...

Here's code from something I wrote a few weeks ago... it's .NET 2.0 and
C#, so you will have to play, but it works great.

string fullpath = @"c:\windows\temp\" + excelFileName;

using (FileStream fs = new FileStream(fullpath,
FileMode.CreateNew, FileAccess.Write, FileShare.Write)) {
fs.Write(file, 0, file.Length);
}

// FileInfo fileInfo = new FileInfo(fullpath);
Response.Buffer = true;
Response.Clear( );
Response.ClearContent( );
Response.ClearHeaders( );

Response.AddHeader("Content-Disposition", "attachment;
filename=" + "AutoGeneratedReport.xls");
Response.AddHeader("Content-Length", file.Length.ToString(
));
Response.ContentType = "application/vnd.ms-excel";
Response.WriteFile(fullpath);
Response.Flush( );

David Betz
http://davidbetz.net/dynamicbliss/
http://davidbetz.net/winfx/
 
G

Guest

Thanks David. I'll test with this. But could you explain why the code is not
work only on one server?

Frank
 
G

Guest

Hi Frank,

we have the same problem at our customers web server. :-( Were you able to
solve your problem? ;-)

Regards,
Alex
 
G

Guest

Problem still there! I uses this code and tested. I got same empty file.
Any idea ?
Thanks,
Frank
 

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

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top