By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,354 Members | 1,042 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,354 IT Pros & Developers. It's quick & easy.

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

P: n/a

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



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


Nov 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.