title: Upload file with input type file in form and c# HttpPostedFile
body: <p>I try to user an input type file to upload a file but my code don't work.</p>
  
  <p>the variable "filePosted" stay to null value.</p>
  
  <p>My code :</p>
  
  <p>HTML :</p>
  
  <pre><code>    &lt;form method="post" name="gestionmembre" runat="server" enctype="multipart/form-data"&gt;
          @using (Html.BeginForm()){
                  &lt;label class="lmembre" for="nom"&gt;Nom:&lt;/label&gt;@Html.TextBox("nom")&lt;br /&gt;
                  &lt;label class="lmembre" for="prenom"&gt;Prénom:&lt;/label&gt;@Html.TextBox("prenom", Request["Prenom"])&lt;br /&gt;
                  &lt;label class="lmembre" for="mail"&gt;Mail:&lt;/label&gt;@Html.TextBox("mail", Request["mail"])&lt;br /&gt;
                  &lt;label class="lmembre" for="photo"&gt;Photo:&lt;/label&gt;&lt;input id="phototelecharge" type="file" name="photo" value="Télécharger photo"/&gt; &lt;br /&gt; 
                  &lt;div class="errorform"&gt;@Html.ValidationSummary()&lt;/div&gt;
                  &lt;input id="ajoutmembre" type="submit" name="boutonmembre" value="Ajouter"/&gt;
      }
      &lt;/form&gt;
  </code></pre>
  
  <p>I don't know if I have to put this atributes in form tag (method runat enctype).</p>
  
  <p>now, in the controler, in block to receive form values, I put :</p>
  
  <pre><code>        else if (Request["boutonmembre"] == "Ajouter")
          {
              //Traitement de l'upload de l'image
  
              HttpPostedFile filePosted;
              filePosted = System.Web.HttpContext.Current.Request.Files["phototelecharge"];
  
  
              if (filePosted != null &amp;&amp; filePosted.ContentLength &gt; 0)
              {
                  string fileNameApplication = System.IO.Path.GetFileName(filePosted.FileName);
                  string fileExtensionApplication = System.IO.Path.GetExtension(fileNameApplication);
  
                  // generating a random guid for a new file at server for the uploaded file
                  string newFile = Guid.NewGuid().ToString() + fileExtensionApplication;
                  // getting a valid server path to save
                  string filePath = System.IO.Path.Combine(Server.MapPath("uploads"), newFile);
  
                  if (fileNameApplication != String.Empty)
                  {
                      filePosted.SaveAs(filePath);
                  }
              }
          }
  </code></pre>
  
  <p>The problem is in :</p>
  
  <pre><code>            filePosted = System.Web.HttpContext.Current.Request.Files["phototelecharge"];
  </code></pre>
  
  <p>The variable fileposted is null.</p>
  
  <p>In the webpage, I select a file fro a disk and the path of the file is realy indicate in the textbox.</p>
  
  <p>Tks for help me.
  David</p>