title: Delete image from folder using data list
body: <p>I display some images in a DataList by getting the images from folder. Now, I want to delete the image in folder when I click the Delete button in my Datalist.</p>
  
  <p>My problem is that I'm not able to get the file name from:</p>
  
  <pre><code>string fileName = e.CommandArgument.ToString();
  </code></pre>
  
  <p>I tried several solutions but did not get a right solution.</p>
  
  <p><strong>Html Markup:</strong></p>
  
  <pre><code>&lt;asp:DataList OnDeleteCommand="gvImages_DeleteCommand" ID="gvImages" RepeatColumns="5" 
                RepeatDirection="Horizontal" GridLines="Horizontal" runat="server" 
                BorderColor="#336699" BorderStyle="Solid" ShowHeader="true"&gt;
      &lt;ItemTemplate&gt;
      &lt;center&gt;
          &lt;table&gt;
              &lt;tr&gt;
                  &lt;td style="width: 90px; height: 90px"&gt;
                      &lt;img id="PICID" runat="server" src='&lt;%# Container.DataItem %&gt;' alt='' 
                           style="height: 100px; width: 100px;" /&gt;&lt;br /&gt;
                      &lt;asp:Button ID="Delete" Height="22px" CommandName="Delete" 
                                  Width="100px" runat="server" Text="Delete Picture" /&gt;&lt;br /&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
      &lt;/center&gt;
      &lt;/ItemTemplate&gt;
  &lt;/asp:DataList&gt;
  </code></pre>
  
  <p><strong>Code-behind:</strong></p>
  
  <pre><code>protected void gvImages_DeleteCommand(object source, DataListCommandEventArgs e)
  {
      //you can hold filename on Button's  CommandArgument 
  
      string fileName = e.CommandArgument.ToString();
  
     // here i can not get the file name to delete it from the folder
  
      File.Delete(Server.MapPath(fileName));
  
      FileInfo fInfo;
  
      fInfo = new FileInfo(fileName);
  
      fInfo.Delete();
  
      gvImages.DataBind();
  }
  </code></pre>