By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,034 Members | 1,777 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,034 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.