title: How do I remove duplicates from an asp.net dropdown list being populated by files names from a directory?
body: <p>I have an asp.net C# webform project.  I have created a dropdown list that is bound to a local upload directory. The directory contains video files.  Each video has 3 file extension (mp4, ogv, and webm). I only want one of each file name to appear in the list without an extension. Currently my dropdown list looks like this:</p>
  
  <pre><code>video-1.mp4
  video-1.ogv
  video-1.webm
  video-2.mp4
  video-2.ogv
  video-2.webm
  </code></pre>
  
  <p>I want the list to look like this:</p>
  
  <pre><code>video-1
  video-2
  </code></pre>
  
  <p>Here is my code behind:</p>
  
  <pre><code>  protected void Page_Load(object sender, EventArgs e)
    {
      if (!IsPostBack)
      {
        BindGrid();
      }
  
      if (!IsPostBack)
      {
        string[] filePaths = Directory.GetFiles(Server.MapPath("~/Uploads/"));
        List&lt;ListItem&gt; files = new List&lt;ListItem&gt;();
        foreach (string filePath in filePaths)
        {
          var item = new ListItem(Path.GetFileNameWithoutExtension(filePath), filePath);
          if (!files.Contains(item))
          files.Add(new ListItem(Path.GetFileName(filePath), filePath));
        }
        DropDownList1.DataSource = files;
        DropDownList1.DataTextField = "";
        DropDownList1.DataValueField = "";
        DropDownList1.DataBind();
      }
    }
    protected void BindGrid()
    {
      string[] filePaths = Directory.GetFiles(Server.MapPath("~/Uploads/"));
      List&lt;ListItem&gt; files = new List&lt;ListItem&gt;();
      foreach (string filePath in filePaths)
      {
        files.Add(new ListItem(Path.GetFileName(filePath), filePath));
      }
      GridView1.DataSource = files;
      GridView1.DataBind();
    }
  </code></pre>
  
  <p>This is what my current dropdown list looks like.  I want to remove the duplicates.</p>
  
  <p><a href="https://i.stack.imgur.com/YGgd3.png" rel="nofollow noreferrer">Dropdown list with duplicates</a></p>