You must Sign In to post a response.
  • Category: ASP.NET

    How to Create Hyperlink to uploaded files in

    Hi all how to create a link to uploaded files to view the uploaded file using hyperlink and when I was uploading only the first name is displaying I want all the file names to display and create a hyperlink to view the files which have uploaded.
    This is the code in aspx.
    <div style="text-align:right;width:400px"><asp:FileUpload ID="FileUpload1" runat="server" AllowMultiple="true"/>
    <br />
    <br />
    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
    Text="Upload Document" /><br />
    <asp:Label ID="Label1" runat="server"></asp:Label>
    and Below is the vb code

    Protected Sub Button1_Click(ByVal sender As Object, _
    ByVal e As System.EventArgs)
    If FileUpload1.HasFile Then
    FileUpload1.SaveAs("\\Destinationpath\testing\\" & _
    Label1.Text =
    FileUpload1.FileName & "<br>"
    Catch ex As Exception
    Label1.Text = "ERROR: " & ex.Message.ToString()
    End Try
    Label1.Text = "You have not specified a file."
    End If
    End Sub
    Can Anyone suggest me.Thanks
  • #763913
    Hai Nagendra,
    You can use the Server.MapPath to get the path of the file which was saved.
    You can use the below code snippet:

    var fileName= HttpContext.Current.Server.MapPath("//Destinationpath/testing/"+ fileName);

    Hope it will be helpful to you.

    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)

  • #763916
    Get the list of files from the uploaded folder in the code behind file. Then assign the list as data source for a grid view and do databind.

    In the Aspx you can show the link.

    <asp:GridView ID="GV1" runat="server" AutoGenerateColumns="False" EnableViewState="False"
    AllowPaging="True" AllowSorting="True"
    <asp:TemplateField HeaderText = "Lesson Plan " ItemStyle-Width="120">
    <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("UploadedFile", "~/{0}") %>'
    Text='<%# Eval("UploadedFile") %>' Target="_blank" />

    By Nathan
    Direction is important than speed

  • #763920
    Hi Nathan it doesn't work I don't want to display in gridview

  • #763921
    Hi Pawan the above code which I have pasted will display the path name my aim is to display all path names the above code will display only one path name if I choose multiple files also I have to display multiple file names and hyperlink to that uploaded files to view the file

  • #763926
    simple you can use gridview to show uploaded files, checkout following aspx file
    <asp:FileUpload ID="FileUpload1" runat="server" />
    <asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="UploadFile" />
    <hr />
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" EmptyDataText = "No files uploaded">
    <asp:BoundField DataField="Text" HeaderText="File Name" />
    <asp:LinkButton ID="lnkDownload" Text = "Download" CommandArgument = '<%# Eval("Value") %>' runat="server" OnClick = "DownloadFile"></asp:LinkButton>
    <asp:LinkButton ID = "lnkDelete" Text = "Delete" CommandArgument = '<%# Eval("Value") %>' runat = "server" OnClick = "DeleteFile" />

    then you can upload file and show it in gridview
    see below link for more details

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #763933
    Hi Prasad it doesn't view the file it just shows download

  • #763943

    As per my understanding the post, first you need to get the files list and then bind that to your UI as you want.

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • #763950
    Hi Naveen
    Yes should get the list of files and have the link to view the files

  • #763951
    Hi nagendra,

    Then what you want?

    You want code for that?

    Please elaborate your requirement. If you want code just Google it you can get best snippet for the same.

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • #763952
    Hi Naveen what my aim is if u run my code you can see only one file name will display even if you select multiple files so I want to display all the file names and want to create hyperlink to those files when we click that file name it should open the file. I have searched many blogs and made changes to my code many times but dint work. can you please suggest the best solution

  • #763965
    Hi nagendra,

    As per your code when you click button you are uploaded file and show that file information in label, if you want to see the list of files you need to get those list, and using grid view control you can show all those files.

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

Sign In to post your comments