Click here to Skip to main content
15,884,952 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
IN WINDOWS FORM APPLICATION

private void button1_Click(object sender, EventArgs e)
       {
           DialogResult dr = openFileDialog1.ShowDialog();
           if (dr == DialogResult.OK)
           {
               string filename = openFileDialog1.FileName;
               Bitmap bt = new Bitmap(filename);
               int x= bt.Width;

}

IN WEB APPLICATION

C#
protected void Button1_Click(object sender, EventArgs e)
   {
       if (FileUpload1.HasFile)
       {
           string filename = FileUpload1.PostedFile.FileName;
           Bitmap bt = new Bitmap(filename); <------Parameter is not valid
            int x = bt.Width;

}

I want to get Width of image which is uploaded by using fileupload control in web application and OpenFileDialog in windows form app..
I get the size in windows form using the same logic ...but, when the same logic is implemented in web based it gives an error 'Parameters is not valid'...
Plz explain and give the exact code to get width....
Thanks.
Posted

1 solution

Hi,

It may be a file permissions issue, you need to ensure that the "IUSR" account for your site has read access to the image file.

To do this -
R-click the file, Properties, Select the "Security" tab - you will have a list of users who have access to the file. A quick check is to add "Everyone" with read priviliges. To keep it locked to your ASP.Net instance only you should start IIS Manager, r-click your app pool and the Identity is the user your app runs under.

Ref: http://stackoverflow.com/questions/7636805/parameter-is-not-valid-error-when-creating-new-bitmap[^]
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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