How to open a .txt file from ASP.NET

  • Thread starter Thread starter ESPN Lover
  • Start date Start date
E

ESPN Lover

Here's a quick function to load the entire text file into a string.

private string LoadFile( string file )
{
string contents = "";
using(StreamReader sr = new StreamReader(file))
{
contents = sr.ReadToEnd();
}
return contents;
}
 
Oh, and the format for calling the LoadFile function might be like:

string filesContents = LoadFile( "c:\\temp\\mytext.txt")

or like

string filesContents = LoadFile(@"c:\temp\mytext.txt") // in this example,
the @ sign automatically escapes the backslashes!
 
Hi group!!! I am new in the ASP.NET programming. I am trying to open a
..txt file but I can't do it.

I am using: but i don't know if its the right way. Thanks for help me.
Dim proc As New System.Diagnostics.Process

proc.Start(file:///C:/bitacora.txt)
 
Where is the application going to be "run" on...client or server?

Once the .txt file is in notepad, what is going to happen to it?
 
I think, I din't be clear with the question.

I want to open the .txt file within an aplication... like Notepad, Excel,
etc. Not just read it.

Thanks...
 
Even though this seems easy, this is a really difficult task without the
end-user openning the application themselves since if you stream text down,
most browsers will display it as is. Plus, there's no known way to launch
applications on a client's machine via a web page. Who's to say they even
have the application on their computer? Even if they did, it'd be a big
security hole to allow a web page to launch programs on someone's machine.

Tell us what exactly is the requirements are, and there may be other ways to
handle this.
 
The application is going to be run on client. And I just want to show the
file on the notepad.
 
Thanks, Now I understand that is difficult in that way, I'll try showing
the information in a container control.

Thanks again for your time.
 
Having an application on a client-side run is not impossible if you try to
use client script like the following;
'----------------------------------------------
<script language="vbscript">
Sub cmdExcel1_onclick()
set appXl = createobject("excel.application")
With appXl
.Workbooks.Add
.Worksheets.Add
End With

appXl.Visible = True
exlrowCnt = exlrowCnt + 1
appXl.cells.Font.Size = 10
appXl.Columns("A:A").Select
appXl.selection.ColumnWidth = 20
appXl.Columns("B:CZ").Select
appXl.selection.ColumnWidth = 5
appXl.Columns("B:B").Select
appXl.ActiveWindow.FreezePanes = True

appXl.cells(1,1) = 2394023034
End Sub
</script>

<input type=button value="get Excel" name="cmdExcel1">
'----------------------------------------------
the thing is when you try to write a data( calculated or managed by server)
on the client's application.
of course, this can be done by the function "RegisterClientScriptBlock()"
with the asp.net. (refer to the msdn about
"Page.RegisterClientScriptBlock()") thogh,
do i really have to concatenate string values and server-side value together?

i hope any one help me...
 

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

Back
Top