473,383 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

How to open text file (.log, .txt etc) in notepad from aspnet

Hi expert,
I have a small web application in C# and ASP.Net and I want to open a file
in notepad when clicked on a linked button. Here is hander code when clicked
on the link button. It can open a process of notepad on the server , but
does not open the file in notepad. What am I doing wrong? can you show me how
to do it please? What I am doing here is : I have datagrid data and when
clicked on linkbutton (logFile), it finds the row identifier and the n
check if any log file exists for that row. If exists, then it should open log
file for that row. When cliked on the link button, it should execute the
ItemClick eventHander.

private void ItemClick(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
//if (((LinkButton)e.CommandSource).CommandName == "SelectItem")
//if (((LinkButton)e.CommandSource).CommandName == "GetLogFile")
try
{

//
//get the row index
int intIndex = (int)dgJobname.DataKeys[e.Item.ItemIndex];
string jobID = ((TextBox)e.Item.Cells[0].Controls[0]).Text;
dvJobStep.RowFilter = "job_id = '" + jobID + "'";
foreach( DataRowView drv in dvJobStep)
{
if (drv["output_file_name"].ToString() != null)
outfile = drv["output_file_name"].ToString();
outfile = outfile.Replace(":","$");
}
// Get the UNC file path
correctfile = @"\\" + Session["ServerName"] + @"\" + outfile;
//checking correct file path
lblError.Text = correctfile;

Process proc = new Process();
//ProcessStartInfo oStartInfo = new ProcessStartInfo();

proc.StartInfo.FileName = "notep ad.exe";
proc.StartInfo.Arguments = correctfile;
//notePad.StartInfo.Arguments = outfile;

proc.Start();
//dgJobname.DataBind();
}
catch(Exception ex)
{
Response.Write(ex.Message);
}
//dgJobname.DataBind();
//Response.Write(outfile);
}
Thank you so much for your help.

Rabindra

Nov 19 '05 #1
3 4828
Other than the apparent misspelling of notepad ( "notep ad.exe";) as the
process start argument, the culprit would likely be an inability to spawn
window based applications on the web server without usually having to go
through hoops.

I'm a bit puzzled as to why you would want to do this, all notepad can give
you is text output, and you can do that with three simple lines of code

// create a writer and open the file
TextWriter tw = new StreamWriter("date.txt");

// write a line of text to the file
tw.WriteLine(DateTime.Now);

// close the stream
tw.Close();

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"RN Das" <RN***@discussions.microsoft.com> wrote in message
news:A3**********************************@microsof t.com...
Hi expert,
I have a small web application in C# and ASP.Net and I want to open a file
in notepad when clicked on a linked button. Here is hander code when
clicked
on the link button. It can open a process of notepad on the server , but
does not open the file in notepad. What am I doing wrong? can you show me
how
to do it please? What I am doing here is : I have datagrid data and when
clicked on linkbutton (logFile), it finds the row identifier and the n
check if any log file exists for that row. If exists, then it should open
log
file for that row. When cliked on the link button, it should execute the
ItemClick eventHander.

private void ItemClick(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
//if (((LinkButton)e.CommandSource).CommandName == "SelectItem")
//if (((LinkButton)e.CommandSource).CommandName == "GetLogFile")
try
{

//
//get the row index
int intIndex = (int)dgJobname.DataKeys[e.Item.ItemIndex];
string jobID = ((TextBox)e.Item.Cells[0].Controls[0]).Text;
dvJobStep.RowFilter = "job_id = '" + jobID + "'";
foreach( DataRowView drv in dvJobStep)
{
if (drv["output_file_name"].ToString() != null)
outfile = drv["output_file_name"].ToString();
outfile = outfile.Replace(":","$");
}
// Get the UNC file path
correctfile = @"\\" + Session["ServerName"] + @"\" + outfile;
//checking correct file path
lblError.Text = correctfile;

Process proc = new Process();
//ProcessStartInfo oStartInfo = new ProcessStartInfo();

proc.StartInfo.FileName = "notep ad.exe";
proc.StartInfo.Arguments = correctfile;
//notePad.StartInfo.Arguments = outfile;

proc.Start();
//dgJobname.DataBind();
}
catch(Exception ex)
{
Response.Write(ex.Message);
}
//dgJobname.DataBind();
//Response.Write(outfile);
}
Thank you so much for your help.

Rabindra

Nov 19 '05 #2
Besides that, if Notepad is launched it will be launched on the server, not
on the client, since no asp.net code is ran on the client. The only thing
that is sent back is generated HTML output.

--
TDAVISJR
aka - Tampa.NET Koder
"John Timney (ASP.NET MVP)" <ti*****@despammed.com> wrote in message
news:eX*************@TK2MSFTNGP10.phx.gbl...
Other than the apparent misspelling of notepad ( "notep ad.exe";) as the
process start argument, the culprit would likely be an inability to spawn
window based applications on the web server without usually having to go
through hoops.

I'm a bit puzzled as to why you would want to do this, all notepad can
give you is text output, and you can do that with three simple lines of
code

// create a writer and open the file
TextWriter tw = new StreamWriter("date.txt");

// write a line of text to the file
tw.WriteLine(DateTime.Now);

// close the stream
tw.Close();

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"RN Das" <RN***@discussions.microsoft.com> wrote in message
news:A3**********************************@microsof t.com...
Hi expert,
I have a small web application in C# and ASP.Net and I want to open a
file
in notepad when clicked on a linked button. Here is hander code when
clicked
on the link button. It can open a process of notepad on the server , but
does not open the file in notepad. What am I doing wrong? can you show me
how
to do it please? What I am doing here is : I have datagrid data and when
clicked on linkbutton (logFile), it finds the row identifier and the n
check if any log file exists for that row. If exists, then it should open
log
file for that row. When cliked on the link button, it should execute the
ItemClick eventHander.

private void ItemClick(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
//if (((LinkButton)e.CommandSource).CommandName == "SelectItem")
//if (((LinkButton)e.CommandSource).CommandName == "GetLogFile")
try
{

//
//get the row index
int intIndex = (int)dgJobname.DataKeys[e.Item.ItemIndex];
string jobID = ((TextBox)e.Item.Cells[0].Controls[0]).Text;
dvJobStep.RowFilter = "job_id = '" + jobID + "'";
foreach( DataRowView drv in dvJobStep)
{
if (drv["output_file_name"].ToString() != null)
outfile = drv["output_file_name"].ToString();
outfile = outfile.Replace(":","$");
}
// Get the UNC file path
correctfile = @"\\" + Session["ServerName"] + @"\" + outfile;
//checking correct file path
lblError.Text = correctfile;

Process proc = new Process();
//ProcessStartInfo oStartInfo = new ProcessStartInfo();

proc.StartInfo.FileName = "notep ad.exe";
proc.StartInfo.Arguments = correctfile;
//notePad.StartInfo.Arguments = outfile;

proc.Start();
//dgJobname.DataBind();
}
catch(Exception ex)
{
Response.Write(ex.Message);
}
//dgJobname.DataBind();
//Response.Write(outfile);
}
Thank you so much for your help.

Rabindra


Nov 19 '05 #3
What would you do once Notepad is opened on the *server* ? (don't you want
to open a text file client side ?)

You may want to explain what you are trying to do so that someone can
suggest perhaps another approach....

Patrice

--

"RN Das" <RN***@discussions.microsoft.com> a écrit dans le message de
news:A3**********************************@microsof t.com...
Hi expert,
I have a small web application in C# and ASP.Net and I want to open a file in notepad when clicked on a linked button. Here is hander code when clicked on the link button. It can open a process of notepad on the server , but
does not open the file in notepad. What am I doing wrong? can you show me how to do it please? What I am doing here is : I have datagrid data and when
clicked on linkbutton (logFile), it finds the row identifier and the n
check if any log file exists for that row. If exists, then it should open log file for that row. When cliked on the link button, it should execute the
ItemClick eventHander.

private void ItemClick(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
//if (((LinkButton)e.CommandSource).CommandName == "SelectItem")
//if (((LinkButton)e.CommandSource).CommandName == "GetLogFile")
try
{

//
//get the row index
int intIndex = (int)dgJobname.DataKeys[e.Item.ItemIndex];
string jobID = ((TextBox)e.Item.Cells[0].Controls[0]).Text;
dvJobStep.RowFilter = "job_id = '" + jobID + "'";
foreach( DataRowView drv in dvJobStep)
{
if (drv["output_file_name"].ToString() != null)
outfile = drv["output_file_name"].ToString();
outfile = outfile.Replace(":","$");
}
// Get the UNC file path
correctfile = @"\\" + Session["ServerName"] + @"\" + outfile;
//checking correct file path
lblError.Text = correctfile;

Process proc = new Process();
//ProcessStartInfo oStartInfo = new ProcessStartInfo();

proc.StartInfo.FileName = "notep ad.exe";
proc.StartInfo.Arguments = correctfile;
//notePad.StartInfo.Arguments = outfile;

proc.Start();
//dgJobname.DataBind();
}
catch(Exception ex)
{
Response.Write(ex.Message);
}
//dgJobname.DataBind();
//Response.Write(outfile);
}
Thank you so much for your help.

Rabindra

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jesper | last post by:
How can I open a textfile from C# using notepad (or the user assigned application for this).
2
by: preetish | last post by:
Hi, I am a total novice to VC++..I have a dialog based application developed using MFC...my requirement is to open a file (with .dat or ..txt ext) invoking Notepad from my application. The user...
1
by: RNDAS | last post by:
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...
3
by: sohan | last post by:
hi I have hyperlink column in a datagrid. The column contains the name of a text file. I am able to appendthe full path of the file. The file is on D drive on the server. But on clicking on...
13
by: Chris Johnson | last post by:
I have what seems to be such a simple thing yet I cannot figure out how to do it. I am using a streamwriter to build a text file. At the end of the process I want to open that same text file in...
0
by: PFancy | last post by:
Hi, Not sure if anyone can help. I have writen some code that will allow users to edit a txt file (it's actually an xml file) in notepad. I can get notepad to open correctly with the correct file,...
1
by: sydmil | last post by:
Hello, I am relatively new to VB6 and I was wondering if anyone could show me an example of a VB6 code to do the following: Open text file (which is a column of numbers) in excel - comma...
4
by: miroku800 | last post by:
the resulting printout looks like this 1,blue,12345678,54 2,red,00001234,6 3,blue,12345678,63 4,blue,12345678,65 5,red,00001234,17 Is there any way to format it into columns and then print it...
2
by: vijendra singh | last post by:
I have created a notepad in c#. Now i want to open a text file in my notepad. but i dont know how to do that, can anybody help me?
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.