locked
FileUploaf RRS feed

  • Question

  • User-169979396 posted

    Hello..
    How I can determine the width and Height for the PostedFile in FileUpload.

    Monday, April 12, 2010 10:44 AM

Answers

  • User188494879 posted

    If its a image you can do this:

    Dim s As Stream = oPostedFile.InputStream 
    Dim i As Image = System.Drawing.Image.FromStream(s) 
     
    intFileWidth = i.PhysicalDimension.Width 
    intFileHeight = i.PhysicalDimension.Height


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 12, 2010 10:54 AM
  • User188494879 posted
    Stream s = oPostedFile.InputStream; 
        Image i = System.Drawing.Image.FromStream(s); 
        
        intFileWidth = i.PhysicalDimension.Width; 
        intFileHeight = i.PhysicalDimension.Height;


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 12, 2010 12:01 PM
  • User188494879 posted
    Stream s = FileUpload1.PostedFile.InputStream; 
    Image i = System.Drawing.Image.FromStream(s); 
        
    intFileWidth = i.PhysicalDimension.Width; 
    intFileHeight = i.PhysicalDimension.Height;


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 12, 2010 12:27 PM
  • User188494879 posted

    ok. Try it like this.

    In the button click event as you have above add this:

     System.Drawing.Image postedFile = System.Drawing.Image.FromStream(FileUpload1.PostedFile.InputStream);
          
     float UploadedImageWidth = postedFile.PhysicalDimension.Width;
     float UploadedImageHeight = postedFile.PhysicalDimension.Height;


    The above should work for Image files 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 12, 2010 2:53 PM

All replies

  • User188494879 posted

    If its a image you can do this:

    Dim s As Stream = oPostedFile.InputStream 
    Dim i As Image = System.Drawing.Image.FromStream(s) 
     
    intFileWidth = i.PhysicalDimension.Width 
    intFileHeight = i.PhysicalDimension.Height


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 12, 2010 10:54 AM
  • User560403387 posted

    I would use the following overload of the FromStream method:

    Dim i As Image = System.Drawing.Image.FromStream(s, False, False)    


    (http://msdn.microsoft.com/en-us/library/21zw9ah6.aspx

    Setting the validateImageData parameter to false will cause the image to load much faster because not all data needs to be loaded into the memory.

    Menno

    Monday, April 12, 2010 11:08 AM
  • User-169979396 posted

    Sory,

    I need the code whith c#

    Monday, April 12, 2010 11:59 AM
  • User188494879 posted
    Stream s = oPostedFile.InputStream; 
        Image i = System.Drawing.Image.FromStream(s); 
        
        intFileWidth = i.PhysicalDimension.Width; 
        intFileHeight = i.PhysicalDimension.Height;


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 12, 2010 12:01 PM
  • User-169979396 posted

    This error is appeared


    Compiler Error Message: CS0246: The type or namespace name 'Stream' could not be found (are you missing a using directive or an assembly reference?)

    Monday, April 12, 2010 12:08 PM
  • User188494879 posted

    Add namespace:

    using System.IO; 

    Monday, April 12, 2010 12:13 PM
  • User-169979396 posted

    sory,

    I dont know how I can use it.

    Please guide me.

    my FileUpload  id is  "FileUpload1"

    so how I can use the above code

     please help me.

    Monday, April 12, 2010 12:20 PM
  • User188494879 posted
    Stream s = FileUpload1.PostedFile.InputStream; 
    Image i = System.Drawing.Image.FromStream(s); 
        
    intFileWidth = i.PhysicalDimension.Width; 
    intFileHeight = i.PhysicalDimension.Height;


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 12, 2010 12:27 PM
  • User-169979396 posted

    Also this error is occurred

    Compiler Error Message: CS0029: Cannot implicitly convert type 'System.Drawing.Image' to 'System.Web.UI.WebControls.Image'

    Monday, April 12, 2010 12:58 PM
  • User-169979396 posted

    I used this code

    protected void Button1_Click(object sender, EventArgs e)
        {
             Stream s = FileUpload1.PostedFile.InputStream;   
            Image i= System.Drawing.Image.FromStream(s);   
                          
            intFileWidth = i.PhysicalDimension.Width;   
            intFileHeight = i.PhysicalDimension.Height;  
            
          
        }

    but this error occurred

    Compiler Error Message: CS0029: Cannot implicitly convert type 'System.Drawing.Image' to 'System.Web.UI.WebControls.Image'


    Please Help me.


    Monday, April 12, 2010 2:34 PM
  • User188494879 posted

    ok. Try it like this.

    In the button click event as you have above add this:

     System.Drawing.Image postedFile = System.Drawing.Image.FromStream(FileUpload1.PostedFile.InputStream);
          
     float UploadedImageWidth = postedFile.PhysicalDimension.Width;
     float UploadedImageHeight = postedFile.PhysicalDimension.Height;


    The above should work for Image files 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 12, 2010 2:53 PM