title: asp.net file upload (how to create a hyperlink to uploaded documents, displayed in my gridview)
body: <p>Afternoon All,</p>
  
  <p>I have a simple file upload tutorial that i have completed for a site that i am developing in visual studio 2010.</p>
  
  <p>I just want to enhance the gridview that shows the uploaded file by making the file a link to that document in the gridview. This will enable users to then upload the file and view the file by pressing a link in the gridview to view the file.</p>
  
  <p>Here is my code so far...</p>
  
  <pre><code>&lt;form id="form1" runat="server"&gt;
  &lt;div&gt; 
  &lt;table style="width: 90%"&gt; 
     &lt;tr&gt; 
        &lt;td style="width: 100px"&gt; Single File Upload:&lt;br /&gt;
        &lt;asp:FileUpload ID="FileUpload1" runat="server" /&gt;&lt;br /&gt;
        &lt;asp:Button ID="buttonUpload" runat="server" Text="Upload" /&gt;&lt;br /&gt;
  &lt;br /&gt;
         &lt;asp:GridView ID="UploadedFiles" DataSource="&lt;%# GetUploadList() %&gt;" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None"&gt; 
          &lt;FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /&gt;
          &lt;RowStyle BackColor="#EFF3FB" /&gt;
          &lt;EditRowStyle BackColor="#2461BF" /&gt;
          &lt;SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /&gt;
          &lt;PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /&gt;
          &lt;HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /&gt;
          &lt;AlternatingRowStyle BackColor="White" /&gt;
        &lt;/asp:GridView&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/div&gt;
  &lt;/form&gt; 
  </code></pre>
  
  <p>And here is the .VB page</p>
  
  <pre><code>Partial Class test
  Inherits System.Web.UI.Page
  
  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      If Not IsPostBack Then
          UploadedFiles.DataBind()
      End If
  End Sub
  
      Protected Function GetUploadList() As String()
      Dim folder As String = Server.MapPath("~/Uploads")
      Dim files() As String = Directory.GetFiles(folder)
      Dim fileNames(files.Length - 1) As String
      Array.Sort(files)
  
      For i As Integer = 0 To files.Length - 1
          fileNames(i) = Path.GetFileName(files(i))
      Next
  
      Return fileNames
  End Function
  
   Protected Sub UploadThisFile(ByVal upload As FileUpload)
      If upload.HasFile Then
          Dim theFileName As String = Path.Combine(Server.MapPath("~/Uploads"), upload.FileName)
          If File.Exists(theFileName) Then
              File.Delete(theFileName)
          End If
          upload.SaveAs(theFileName)
      End If
  End Sub
  
  Protected Sub buttonUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles buttonUpload.Click
      UploadThisFile(FileUpload1)
      UploadedFiles.DataBind()
  End Sub
  
  End Class
  </code></pre>
  
  <p>Im not too sure on how to add a little extra code into the <code>Protected Sub UploadThisFile(ByVal upload As FileUpload)</code> section.  </p>
  
  <p>Any help to make this static list of items that are available in the Uploads file to a list that holds a link to these individual documents is much appriechiated.</p>
  
  <p>Many thanks in advance,
  Betty</p>