Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to upload fix Size of image in the database.or resize Image on the time of uploading.plz help me
Posted

Try the following :-

C#
string[] sizes = { "B", "KB", "MB", "GB" };
double len = new FileInfo(filename).Length;
int order = 0;
while (len >= 1024 && order + 1 < sizes.Length) {
    order++;
    len = len/1024;
}



string result = String.Format("{0: 0.##} {1}", len, sizes[order]);
 
Share this answer
 
v3
I implemented once validation on size while uploading the image, I used a HTTPHandler to avoid postback.

But your requirement seems different, you want to resize if it not of required size. You can follow the below link



http://stackoverflow.com/questions/254419/asp-net-image-uploading-with-resizing[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900