title: Fileupload inside detailsview in edit mode
body: <p>Hello i try to add a fileupload inside of a detailsview i attach here some parts from my code:</p>
  
  <pre><code>&lt;asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="586px" 
          DefaultMode="Edit" AutoGenerateRows="False" BorderColor="White" 
          BorderStyle="None" DataSourceID="EntityDataSource1" GridLines="None" DataKeyNames="UserName" OnItemUpdated="DetailsView1_ItemUpdated" ONItemEditing="DetailsView1_ItemEditing"&gt;
  </code></pre>
  
  <p>then the fileupload control is placed inside of template field:</p>
  
  <pre><code> &lt;asp:TemplateField HeaderText="Foto"&gt;
                        &lt;EditItemTemplate&gt;
  
  
  &lt;asp:FileUpload ID="FileUpload1" runat="server" /&gt;
                           &lt;/EditItemTemplate&gt;
       &lt;/asp:TemplateField&gt;
  </code></pre>
  
  <p>and the datasource is :</p>
  
  <pre><code> &lt;asp:EntityDataSource ID="EntityDataSource1" runat="server" 
          ConnectionString="name=mesteriEntities" DefaultContainerName="mesteriEntities" 
          EnableFlattening="False" EntitySetName="Users" 
           EnableUpdate="True" AutoGenerateWhereClause="True" 
      EnableInsert="True"&gt;
           &lt;WhereParameters&gt;
          &lt;asp:SessionParameter Name="UserName" SessionField="New" Type="String" /&gt;
           &lt;/WhereParameters&gt;
      &lt;/asp:EntityDataSource&gt;
  </code></pre>
  
  <p>The code behind:</p>
  
  <pre><code> protected void DetailsView1_ItemEditing(object sender, DetailsViewInsertEventArgs e)
      {
          FileUpload fu1 = (FileUpload)DetailsView1.FindControl("FileUpload1");
          if (fu1 == null)
              e.Cancel = true;
          if (fu1.HasFile)
          {
              try
              {
                  string fileName = Guid.NewGuid().ToString();
                  string virtualFolder = "~/UserPics/";
                  string physicalFolder = Server.MapPath(virtualFolder);
                 // StatusLabel.Text = "Upload status: File uploaded!";
                  string extension = System.IO.Path.GetExtension(fu1.FileName);
                  fu1.SaveAs(System.IO.Path.Combine(physicalFolder, fileName + extension));
                  e.Values["foto"] = System.IO.Path.Combine(physicalFolder, fileName + extension);
              }
              catch (Exception ex)
              {
                Response.Write(ex.Message);
              }
          }
          else
              e.Cancel = true;
  
  
  
      }
  </code></pre>
  
  <p>I'm not sure why doesn't work. It doesn't upload the file on the server and doesn't add reference inside database of the file . Whay i did wrong here?</p>
  
  <p>thank you</p>