How do i open a text file on a button click
-
Hi all, I want to open a readme txt file when user clicks a button. How do i achieve this. Thanks in advance.
-
Hi all, I want to open a readme txt file when user clicks a button. How do i achieve this. Thanks in advance.
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:▒▒〓▒〓▒▒ :^):^):^):^):^):^):^):^):^):^):^):^)
-
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:▒▒〓▒〓▒▒ :^):^):^):^):^):^):^):^):^):^):^):^)
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:▒▒〓▒〓▒▒ :^):^):^):^):^):^):^):^):^):^):^):^)
-
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:▒▒〓▒〓▒▒ :^):^):^):^):^):^):^):^):^):^):^):^)
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.
-
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.
--- 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 .
function fnDownLoadFile() { window.document.getElementById("hello").click(); }
:^):^):^):^):^):^):^):^):^):^):^):^) :^):rose::rose::rose::rose::rose:▒▒〓▒〓▒▒ :^):rose::^):^):^):^)▒〓〓〓〓〓▒ :^):rose::^):^):^):^)▒▒〓▒〓▒▒ :^):rose::^):^):^):^)▒〓〓〓〓〓▒ :^):rose::rose::rose::rose::rose:▒▒〓▒〓▒▒ :^):^):^):^):^):^):^):^):^):^):^):^)
-
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.
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."