Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7934703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:42:55+00:00 2026-06-03T21:42:55+00:00

Afternoon All, I have a simple file upload tutorial that i have completed for

  • 0

Afternoon All,

I have a simple file upload tutorial that i have completed for a site that i am developing in visual studio 2010.

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.

Here is my code so far…

<form id="form1" runat="server">
<div> 
<table style="width: 90%"> 
   <tr> 
      <td style="width: 100px"> Single File Upload:<br />
      <asp:FileUpload ID="FileUpload1" runat="server" /><br />
      <asp:Button ID="buttonUpload" runat="server" Text="Upload" /><br />
<br />
       <asp:GridView ID="UploadedFiles" DataSource="<%# GetUploadList() %>" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None"> 
        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <RowStyle BackColor="#EFF3FB" />
        <EditRowStyle BackColor="#2461BF" />
        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <AlternatingRowStyle BackColor="White" />
      </asp:GridView>
    </td>
  </tr>
</table>
</div>
</form> 

And here is the .VB page

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

Im not too sure on how to add a little extra code into the Protected Sub UploadThisFile(ByVal upload As FileUpload) section.

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.

Many thanks in advance,
Betty

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T21:42:56+00:00Added an answer on June 3, 2026 at 9:42 pm

    Tweat your code this way:

    Generate the tags:

    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
            Dim lnk As String = String.Empty
            Array.Sort(files)
    
            For i As Integer = 0 To files.Length - 1
                lnk = "  <a href=""Uploads/" & files(i).ToString() & """ target=""_blank"">File</a>"
                fileNames(i) = Path.GetFileName(files(i)) & lnk
                lnk = ""
            Next
    
            Return fileNames
    
    End Function
    

    Access each gridview cell to decode the markup:

    Protected Sub UploadedFiles_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles UploadedFiles.RowDataBound
    
            If e.Row.RowType = DataControlRowType.DataRow Then
    
                Dim tcls As TableCellCollection = e.Row.Cells
    
                For Each tc As TableCell In tcls
                    tc.Text = Server.HtmlDecode(tc.Text)
                Next
    
            End If
    
    End Sub    
    

    If you want the “<a>” tag to get generated on your file name you could change each filename this way:

    fileNames(i) = "<a href=""Uploads/" & Path.GetFileName(files(i).ToString()) & """ target=""_blank"">" & Path.GetFileName(files(i)) & "</a>"
    

    Hope it helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Afternoon All, I am using a visual studio 2010. I have a web page
Afternoon All, I have a simple gridview with list items items that have been
Good afternoon all, I have a Java applet that I wish to embed on
Good Afternoon All, I have a wizard control that contains 20 textboxes for part
Good Afternoon All, I have written an SSIS 2005 package that contains a conditional
Very good afternoon to all, The problem I have now is that I can
Afternoon all. I have a gridview that offers a line per line 'feedback' column.
Good afternoon all. I have a page that displays data in a gridview based
Afternoon all I have a lovely webservice call that brings back a list, we'll
Afternoon all. A very simple one for you today from thicky Rich. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.