Download file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Doug Stiers

    Download file

    I have a button on a webform, when the user clicks a file on our network
    will be downloaded to the clients machine. I need the button to initiate the
    download just like a hyperlink without displaying the path like a hyperlink
    would (down on the status bar). The file is an exe so its not something that
    is going to be displayed, it has to be downloaded.

    I've tried Server.Transfer (sFilePath) but that does not work. Can anyone
    help?

    Thanks,
    Doug Stiers


  • bruce barker

    #2
    Re: Download file

    there is no server support for this, but you can override the statusbar with
    client code. just cath the mouseover and change the status message.

    -- bruce (sqlwork.com)



    "Doug Stiers" <stiers@email.c om> wrote in message
    news:eHX3GravDH A.2316@TK2MSFTN GP10.phx.gbl...[color=blue]
    > I have a button on a webform, when the user clicks a file on our network
    > will be downloaded to the clients machine. I need the button to initiate[/color]
    the[color=blue]
    > download just like a hyperlink without displaying the path like a[/color]
    hyperlink[color=blue]
    > would (down on the status bar). The file is an exe so its not something[/color]
    that[color=blue]
    > is going to be displayed, it has to be downloaded.
    >
    > I've tried Server.Transfer (sFilePath) but that does not work. Can anyone
    > help?
    >
    > Thanks,
    > Doug Stiers
    >
    >[/color]


    Comment

    • Ken Cox [Microsoft MVP]

      #3
      Re: Download file

      Hi Doug,

      The best thing is a LinkButton control. If you use the following technique,
      the user will have no idea where the file is coming from but it looks just
      like a hyperlink:

      Private Sub LinkButton1_Cli ck _
      (ByVal sender As System.Object, _
      ByVal e As System.EventArg s) _
      Handles LinkButton1.Cli ck
      Dim FilePath As String = "C:\downloads\s etup.exe"
      Dim FileName As String = "setup.exe"
      'Set the appropriate ContentType.
      Response.Conten tType = "applicatio n/octet-stream"
      Response.AddHea der("Content-Disposition", _
      "attachment ; filename=" & FileName)
      'Write the file directly to the HTTP output stream.
      Response.WriteF ile(FilePath)
      Response.End()
      End Sub

      <form id="Form1" method="post" runat="server">
      <asp:LinkButt on id="LinkButton1 " runat="server"> Click to
      download</asp:LinkButton>
      </form>


      "Doug Stiers" <stiers@email.c om> wrote in message
      news:eHX3GravDH A.2316@TK2MSFTN GP10.phx.gbl...[color=blue]
      > I have a button on a webform, when the user clicks a file on our network
      > will be downloaded to the clients machine. I need the button to initiate[/color]
      the[color=blue]
      > download just like a hyperlink without displaying the path like a[/color]
      hyperlink[color=blue]
      > would (down on the status bar). The file is an exe so its not something[/color]
      that[color=blue]
      > is going to be displayed, it has to be downloaded.
      >
      > I've tried Server.Transfer (sFilePath) but that does not work. Can anyone
      > help?
      >
      > Thanks,
      > Doug Stiers
      >
      >[/color]


      Comment

      Working...