weird....different size between uploading and downloading???

G

Guest

Hi,

I've written code web-based uploading and downloading.
Here is some code for it.

For saving file into MS-SQL database,
SaveFileIntoDB(HttpPostedFile file) {
int fileLength = file.ContentLength;
byte[] fileContent = new byte[fileLength];
int lastPos = file.FileName.LastIndexOf('\\');
fileName = file.FileName.Substring(++lastPos);
file.InputStream.Read(fileContent,0,fileLength);
String fileContentType = file.ContentType;

// Save fileLength,fileName and fileContent into MS-SQL database
// data type of fileLength(column name : filelength) is int
// data type of fileName(column name : filename) is varchar(100)
// data type of fileContent(column name : filecontent) is image.
// data type of fileContent type(column name : contenttype) is
varchar(100)

DB.Save(......);

}

For downloading the file from the DB.

Download() {

// Fetch the file info into db variable from the DB.

int filesize = Convert.ToInt32(db["filesize"].ToString());
byte[] fcontent = db["filecontent"] as byte[];
ms = new MemoryStream();
ms.Position = 0;
ms.Write(fcontent,0,fcontent.Length);
Response.AppendHeader("Content-Disposition",
"filename=" + db["filename"].ToString());
Response.ContentType = db["contenttype"].ToString();
Response.OutputStream.Write(ms.GetBuffer(),0,Convert.ToInt32(ms.Length));
}

For saving the file info to the sql db, it worked as I expected. Also, when
I tried to download the file that I saved into the db, it worked, HOWEVER,
when I checked the filesize, it was DIFFERENT. Do you have any idea why?

For example,

Suppose that I uploaded "A.exe" file into the sql db.
The file size of A. exe was 5113 Bytes.
If I downloaded the A.exe, and then when I checked the file size,
it was 5,896 Bytes.
I think that it should be same size since it was same file.
Always whenever I download the file that I've uploaded, the file size is
slighlty bigger than uploaded file. I really couldn't find any reason....
After downloading, the file seems like working well, but I guess it must be
something wrong since it was different file size.

If you could give any ideas about this issue, I really appreciate it.

Thanks.
 

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,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top