471,073 Members | 1,130 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,073 software developers and data experts.

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

TJ
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,Conve rt.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.

Nov 18 '05 #1
0 1405

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by redneck_kiwi | last post: by
7 posts views Thread by LRW | last post: by
11 posts views Thread by Parrot | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.