C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




how to ristrict the image size to height=400 and size=600


Posted Date: 05 Sep 2008      Total Responses: 5

Posted By: prasanthkumar       Member Level: Gold     Points: 1


how to ristrict the image size to height=400 and size=600

in c#asp.net

i got the answer from sudha

it works

but not works with mozilla

it works with ie

pls provide a solution

=========================================
Use this code to restrict the image size...

if (fileUploadID.HasFile)
{
string fname = fileUploadID.PostedFile.FileName;
System.Drawing.Image img1;
img1 = System.Drawing.Image.FromFile(fname);
int width = Convert.ToInt32(img1.Width);
int height = Convert.ToInt32(img1.Height);
if (width <= 600 && height <= 400)
{
lblerror.Text = "Image size is allowed";
}
else
{
lblerror.Text = "Image size is not allowed";
}
}




Responses

Author: Raju.M    05 Sep 2008Member Level: GoldRating:     Points: 2
it didnot work on Mozilla. becoz Mozilla return only the filename.extention for example if the upload file name is test.jpg,

IE returns file name with its location like C:\\test.jpg but
Mozilla return test.jpg only.
you can chang this by
System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName).ToLower(); its returns full path.
u can change ur code like this


if (fileUploadID.HasFile)
{
string fname = System.IO.Path.GetFileName(fileUploadID.PostedFile.FileName).ToLower();

System.Drawing.Image img1;
img1 = System.Drawing.Image.FromFile(fname);
int width = Convert.ToInt32(img1.Width);
int height = Convert.ToInt32(img1.Height);
if (width <= 600 && height <= 400)
{
lblerror.Text = "Image size is allowed";
}
else
{
lblerror.Text = "Image size is not allowed";
}
}




Author: prasanthkumar    06 Sep 2008Member Level: GoldRating: Revenue Score: 0     Points: 0
Thanks


Author: prasanthkumar    06 Sep 2008Member Level: GoldRating:     Points: 1
i ve tried your code,still it didnt work


Author: Raju.M    07 Sep 2008Member Level: GoldRating:     Points: 6
sorry i didnt check ur reply.
this is working code.


if (FileUpload1.HasFile)
{
byte[] byteArray=FileUpload1.FileBytes;
System.IO.MemoryStream mm = new System.IO.MemoryStream();
mm.Write(byteArray, 0, byteArray.Length);
System.Drawing.Image img1;
img1 = System.Drawing.Image.FromStream(mm);
int width = Convert.ToInt32(img1.Width);
int height = Convert.ToInt32(img1.Height);
if (width <= 600 && height <= 400)
{
lblerror.Text = "Image size is allowed";
}
else
{
lblerror.Text = "Image size is not allowed";
}
mm.Dispose();
}



Author: prasanthkumar    08 Sep 2008Member Level: GoldRating:     Points: 1
thanks, its a great help .at the rt time


Post Reply
You must Sign In to post a response.
Next : globalization
Previous : sessions
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design

accuconference

Contact Us    Privacy Policy    Terms Of Use