473,378 Members | 1,580 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 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 1499

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: redneck_kiwi | last post by:
Hi all: I have a really weird problem. I am developing a customer catalog system for my company and as such have delved into sessions for authentication and access levels. So far, I have managed...
7
by: LRW | last post by:
Below I'll paste my CSS and the HTML in question. But what's happening is, I'm trying to establish a link behavior for a class that's separate from the normal link class. I've established a: 's...
5
by: news | last post by:
I've a site: http://gto.ie-studios.net/products.php that looks perfectly fine in Windows whether with IE or Firefox 1.0. But when viewed in the Linux version of Firefox 1.0, images get misaligned...
4
by: Himanshu | last post by:
hi, Can anybody tell me that thru asp.net using c#, how can we upload and download physical files in any table of SQL Server Database. the uploading part is running successfully but the...
2
by: Verde | last post by:
I currently let users upload files (graphics) to a Web site. I want to limit the size of graphics, so I have the following in Web.config <httpRuntime maxRequestLength="110" /> That works just...
11
by: Parrot | last post by:
Is there any routine I can call to reduce the size of an image file after uploading a file from a client. I am looking to reduce file sizes programmatically using C# in my web page after uploading....
3
by: J055 | last post by:
Hi How do I tell the user he has tried to upload a file which is too big... 1. when the httpRuntime.maxRequestLength has been exceeded and 2. when the uploaded file is under then...
5
by: Steve | last post by:
WSE352 Size of the record exceed its limit I have a C#.Net windows app that calls a FileNet web service. I can run a select against the web service and it returns up to 7,200 records with 5...
4
by: aldonnelley | last post by:
Hi there: a bit of a left-field question, I think. I'm writing a program that analyses image files downloaded with a basic crawler, and it's slow, mainly because I only want to analyse files...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.