title: fileupload control wouldn't work in ASP.NET
body: <p>I'm trying to make a simple uploadfile control with ASP.NET, 
  and it wouldnt work:</p>
  
  <h2>Here's my code(.aspx):</h2>
  
  <pre><code>&lt;form id="form1" runat="server"&gt;
    &lt;div&gt;
      upload a file now.
        &lt;asp:FileUpload ID="fileupload1" runat="server" /&gt;
        &lt;asp:Button  ID="button1"  Text="Upload"  runat="server"  Width="73px" 
              onclick="button1_Click" /&gt;
      &lt;asp:Label ID="Label1" runat="server"  Font-Bold="True"  ForeColor="#000099"&gt;
           &lt;/asp:Label&gt;
    &lt;/div&gt;  
  &lt;/form&gt;
  </code></pre>
  
  <h2>and here's my code behind(.cs):</h2>
  
  <pre><code>if(fileupload1.HasFile)
  {
      try
      {
          if(fileupload1.PostedFile.ContentType ==  "image/jpeg")
          {
              if(fileupload1.PostedFile.ContentLength &lt; 51200000)
              {
                 string  filename = Path.GetFileName(fileupload1.FileName);
                 fileupload1.SaveAs(Server.MapPath("~/img/") + filename);
                 Label1.Text ="File uploaded successfully!";
              }
              else
                  Label1.Text ="File maximum size is 500 Kb";
          }
          else
              Label1.Text ="Only JPEG files are accepted!";
      }
      catch(Exception exc)
      {
          Label1.Text = "The file could not be uploaded. The following error occured: "
                             + exc.Message;
      }
    }
  </code></pre>
  
  <p>the file is not presented in the server.. 
  any thoughts?</p>
  
  <p>when I breakpoint, they all goes valid, the application gets to the code, it all working , but won't save it to the folders.</p>