Topic:   Save As dialog for text file
Jan 18, 2021 14:57 3 Replies 486 Views DIVYA

I want to be able to allow a user at my site to download a text file to their local machine. They should be presented with a save as dialog. I found this code here below. My question is how do I get the filename and path to this sub? I tried a couple of hyperlinks, but they are not working for me. They don't do anything when clicked and the browser doesn't allow the file to open up and be saved. I'm using a gridview. Should I create a button and code each button with a path to the file and a filename? Is it possible to set these as command args in the code behind so when the user clicks the button these paramaters are passed into this sub here and the user is served up a save as dialog?

Public Sub DownloadFile()
        Dim FileName As String = ""
        Dim FilePath As String = ""
        'Dim FilePath As String = AppDomain.CurrentDomain.BaseDirectory & "/App_Data/Uploads/" + FileName
        Dim response As System.Web.HttpResponse = System.Web.HttpContext.Current.Response
        response.ClearContent()
        response.Clear()
        response.ContentType = "text/plain"
        response.AddHeader("Content-Disposition", "attachment; filename=" & FileName & ";")
        response.TransmitFile(FilePath)
        response.Flush()
        response.[End]()
    End Sub

Prev Next
Topic Replies (3)
  1. 1
    idnkx user

    PARTH

    Get the file path, then read it. Use hyperlink button click event.

    Dim fullpath As String = System.IO.Path.GetFullPath("~/App_Data/Uploads/" & FileName)

    1
    idnkx user

    PADMAKEECHU

    Get the file path, then read it. Use hyplinkbutton cllick event
    Dim fullpath As String = System.IO.Path.GetFullPath("~/App_Data/Uploads/" & FileName)
    -

Leave a Reply
Guest User

Not sure what course is right for you?

Choose the right course for you.
Get the help of our experts and find a course that best suits your needs.


Let`s Connect