Open a text file in notepad in C# and ASP.Net

R

RNDAS

Hi,
I have a DataGrid in my web page and there is a column in that
grid which template column with linkButton. When Clicked the
linkButton it should not refresh the page, rather it should open a
file in notepad. I am not able to resolve it. Can you please help
me with code how to do it? I have spent days after days seraching
Web, books with no luck. I am a newbie in .net.

Thanks a lot
Hope someone would be kind enough to provide me a solution.

Das
 
N

Nate Hekman

If I understand right you have a link to a .txt file and you want the file
to open in Notepad rather than the browser. To do that the text file needs
to be sent to the browser with a Content-Disposition: Attachment HTTP
header, like this:

Content-Disposition: Attachment; filename="YourTextFilename.txt"

To send an HTTP header you'll have to generate the text file on demand. So
for example, create a "downloadtextfile.aspx" file that you pass a filename
to (downloadtextfile.aspx?filename=YourTextFilename.txt), and the OnLoad
handler does something like this:

Response.ContentType = "text/plain";
Response.AppendHeader("content-disposition", "attachment; filename=\"" +
Request.QueryString["filename"] + "\"");
Response.Write( /* file contents go here */ );


Nate Hekman
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top