Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How do i open a text file on a button click

How do i open a text file on a button click

Scheduled Pinned Locked Moved ASP.NET
question
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    www Developerof NET
    wrote on last edited by
    #1

    Hi all, I want to open a readme txt file when user clicks a button. How do i achieve this. Thanks in advance.

    X 1 Reply Last reply
    0
    • W www Developerof NET

      Hi all, I want to open a readme txt file when user clicks a button. How do i achieve this. Thanks in advance.

      X Offline
      X Offline
      xibeifeijian
      wrote on last edited by
      #2

      Open read me file in client?I don't think there is anyway without use component.Use reponse to write it in a aspx page. StreamReader rdrTextFile=new StreamReader(txtFilePth); string strContent=rdrTextFile.ReadToEnd();//strContent is the content of the txt file. //response strContent rdrTextFile.Close();

      :^):^):^):^):^):^):^):^):^):^):^):^) :^):rose::rose::rose::rose::rose:▒▒〓▒〓▒▒ :^):rose::^):^):^):^)▒〓〓〓〓〓▒ :^):rose::^):^):^):^)▒▒〓▒〓▒▒ :^):rose::^):^):^):^)▒〓〓〓〓〓▒ :^):rose::rose::rose::rose::rose:▒▒〓▒〓▒▒ :^):^):^):^):^):^):^):^):^):^):^):^)

      X 1 Reply Last reply
      0
      • X xibeifeijian

        Open read me file in client?I don't think there is anyway without use component.Use reponse to write it in a aspx page. StreamReader rdrTextFile=new StreamReader(txtFilePth); string strContent=rdrTextFile.ReadToEnd();//strContent is the content of the txt file. //response strContent rdrTextFile.Close();

        :^):^):^):^):^):^):^):^):^):^):^):^) :^):rose::rose::rose::rose::rose:▒▒〓▒〓▒▒ :^):rose::^):^):^):^)▒〓〓〓〓〓▒ :^):rose::^):^):^):^)▒▒〓▒〓▒▒ :^):rose::^):^):^):^)▒〓〓〓〓〓▒ :^):rose::rose::rose::rose::rose:▒▒〓▒〓▒▒ :^):^):^):^):^):^):^):^):^):^):^):^)

        X Offline
        X Offline
        xibeifeijian
        wrote on last edited by
        #3

        Hi sir,I'm sorry.I think I didn't understand your demand. (1) Set Response's ContentType to "APPLICATION/OCTET-STREAM"; (2) Add a header like: response.AddHeader("Content-Disposition","attachment;filename="+strFileName);//just change the fileName to your real file name. (3)Get a buffer array(use FileStream to get a byte[]); (4)Clear the response; (5)Use Response.OutputStream.Write write the byte array to client. (6)Call Response.End(),otherwise you will see the html of current page in the text file.:-O

        :^):^):^):^):^):^):^):^):^):^):^):^) :^):rose::rose::rose::rose::rose:▒▒〓▒〓▒▒ :^):rose::^):^):^):^)▒〓〓〓〓〓▒ :^):rose::^):^):^):^)▒▒〓▒〓▒▒ :^):rose::^):^):^):^)▒〓〓〓〓〓▒ :^):rose::rose::rose::rose::rose:▒▒〓▒〓▒▒ :^):^):^):^):^):^):^):^):^):^):^):^)

        W 1 Reply Last reply
        0
        • X xibeifeijian

          Hi sir,I'm sorry.I think I didn't understand your demand. (1) Set Response's ContentType to "APPLICATION/OCTET-STREAM"; (2) Add a header like: response.AddHeader("Content-Disposition","attachment;filename="+strFileName);//just change the fileName to your real file name. (3)Get a buffer array(use FileStream to get a byte[]); (4)Clear the response; (5)Use Response.OutputStream.Write write the byte array to client. (6)Call Response.End(),otherwise you will see the html of current page in the text file.:-O

          :^):^):^):^):^):^):^):^):^):^):^):^) :^):rose::rose::rose::rose::rose:▒▒〓▒〓▒▒ :^):rose::^):^):^):^)▒〓〓〓〓〓▒ :^):rose::^):^):^):^)▒▒〓▒〓▒▒ :^):rose::^):^):^):^)▒〓〓〓〓〓▒ :^):rose::rose::rose::rose::rose:▒▒〓▒〓▒▒ :^):^):^):^):^):^):^):^):^):^):^):^)

          W Offline
          W Offline
          www Developerof NET
          wrote on last edited by
          #4

          Sorry for not being clear. I don`t wan`t to read or write to a file!!!. All i need to do is open or download up a notepad file on the client`s machine stored on the server as soon as the user clicks on the help button.I know that i can use a hyperlink set it`s href value to the file but how do i do this on a button click. Or just tell me how do i fire onclick event of that hyperlink on a button click.

          X T 2 Replies Last reply
          0
          • W www Developerof NET

            Sorry for not being clear. I don`t wan`t to read or write to a file!!!. All i need to do is open or download up a notepad file on the client`s machine stored on the server as soon as the user clicks on the help button.I know that i can use a hyperlink set it`s href value to the file but how do i do this on a button click. Or just tell me how do i fire onclick event of that hyperlink on a button click.

            X Offline
            X Offline
            xibeifeijian
            wrote on last edited by
            #5

            --- Or just tell me how do i fire onclick event of that hyperlink on a button click. ---- Give you a example,I can fire it but cannot show a download dialog box.:( Create a and hidden it.Then use a javascript function to fire the event. You must give a id for .

            df

            function fnDownLoadFile() { window.document.getElementById("hello").click(); }

            :^):^):^):^):^):^):^):^):^):^):^):^) :^):rose::rose::rose::rose::rose:▒▒〓▒〓▒▒ :^):rose::^):^):^):^)▒〓〓〓〓〓▒ :^):rose::^):^):^):^)▒▒〓▒〓▒▒ :^):rose::^):^):^):^)▒〓〓〓〓〓▒ :^):rose::rose::rose::rose::rose:▒▒〓▒〓▒▒ :^):^):^):^):^):^):^):^):^):^):^):^)

            1 Reply Last reply
            0
            • W www Developerof NET

              Sorry for not being clear. I don`t wan`t to read or write to a file!!!. All i need to do is open or download up a notepad file on the client`s machine stored on the server as soon as the user clicks on the help button.I know that i can use a hyperlink set it`s href value to the file but how do i do this on a button click. Or just tell me how do i fire onclick event of that hyperlink on a button click.

              T Offline
              T Offline
              The Texas Rattle Snake
              wrote on last edited by
              #6

              Very Simple ... Just put Response.Redirect("C:\Abc.txt"); in the Button_Click() function in the aspx.cs file ! :) "We all have abilities.The difference is how we use it."

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups