Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 533
  • Last Modified:

How do I get he dimensions of an image on upload

I’m trying to upload images but I would like to know the dimensions of the image so I know if it should be auto cropped.  Below is a what I have now, but how do I get the dimension of the image?

string uploadFolder = Request.PhysicalApplicationPath + "/images/";  

if (FileUpload1.HasFile)
   {
      string oldFileName = FileUpload1.FileName.ToString();

      FileInfo info = new FileInfo(FileUpload1.PostedFile.ContentLength.ToString());

string extension = Path.GetExtension(FileUpload1.PostedFile.FileName);

            if (extension.ToLower() == ".jpg" || extension.ToLower() == ".gif" || extension.ToLower() == ".png")
            {
                string fileSize = FileUpload1.Width.Value.ToString();
              
                Label2.Text = info.ToString();
                
            }
            else
            {
                Label1.Text = "This file extension not permitted: " + extension;
            }  


        }

Open in new window

0
bmanmike39
Asked:
bmanmike39
1 Solution
 
Rajar AhmedConsultantCommented:
Try this,
System.Drawing.Bitmap img = new System.Drawing.Bitmap(FileUpload1.PostedFile.InputStream);
int h = img.Height;
int w = img.Width;

Open in new window

0
 
bmanmike39Author Commented:
Thanks!   Just what i needed!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now