Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use NotePad to oppen a text file

Status
Not open for further replies.

markask

Programmer
Apr 28, 2005
167
0
0
GB
Hi,

I run my ASP page by IIS in my PC. In the ASP code, how to use NotePad to oppen a text file?

Thank you in advance.
 
Sorry, I didn't explain clearly. Let me try again:
When you double click a .txt file, normally, NotePad.exe will oppen this .txt. In VB, we can use Shell or API to do this thing. How to do this in ASP?
 
Do you want notepad to open on the web server or on the client computer?
 
Running ASP pages on my PC by IIS, I just need to open the .txt file under Windows XP on my PC. That is on the server.
I can double click the .txt to oppen or open NotePad first then open the .txt from NotePad, but I need to open the .txt by ASP code.....
 
You might try something like this:
[tt]
Set Shell = WScript.CreateObject("WScript.Shell")
Shell.Run "Notepad " & YourFileNameGoesHere
[/tt]

But I wouldn't do this on a live public web server because it wouldnt be long before the server is brought to its knees running 100s of notepads.
 
Thank you.

But why I got error message:
Microsoft VBScript runtime (0x800A01A8)
Object required: ''
 
put this in a .vbs file and run it under administrative privileges:

dim objShell
Set objShell = CreateObject("WScript.Shell")

tell us what you get

-DNG
 
I tried this, no error:
Set Shell = CreateObject("WScript.Shell")
Shell.Run "Notepad " & YourFileNameGoesHere
but it didn't whow the .txt file.
 
This may sound like a silly question but did you use the real file name & path instead of YourFileNameGoesHere ??/

Something like C:\Somefolder\Somefile.txt
 
Not sure if it is applicable in this case but I have done some HTA programming recently and found that I had to make my file paths like this:
C://Documents and Settings/userid/Desktop/myfile.txt

Note the slashes all had to be forward rather than backslashes and I had to double up the slash after the drive letter.
This is using WSH in an HTA file so Explorer is the interpreter. It uses VBA code and has no reliance on ASP or IIS at all. Since the Windows ScriptHost is being called in the examples above the same file/path requirements may apply.

 
Sheco,

Thank you....

Here is my code, all fine except no file to be displayed:
s=request.form("xxxxx")
response.write s & "<br><br>"
filePath = "c:\...\xxx.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
Set txtS = fso_OpenTextFile(filePath,2)
txtS.Write(s)
txtS.close
response.write "(File saved in " & filePath &".)"

Set Shell =CreateObject("WScript.Shell")
Shell.Run "Notepad " & filePath
 
Nice tip theniteowl ... that is definately the sort of thing that I pull my hair out over!
 
theniteowl,

Perhaps, I my problem is the path of NotePad? Can I use Start instead of Run?
 
Did you get an error markask?

If not try looking in the task manager process list to make sure there isnt a phantom notepad.exe running somewhere without any visible interface.
 
Sheco,

My code got no error.
No other NotePad.exe running.
 
I have not tried using WScript.Shell directly within ASP and do not know how the syntax might vary.

Tomorrow I will try and look into my old HTA code. In it I generate an HTML page then export it to a Word document and launch it in Word for viewing. The code is VBA and may be easy enough to modify for ASP usage.
 
Here is a quick bit of code that I used to open up a Word document.

<SCRIPT LANGUAGE="VBScript">
Sub makedoc(filename)
Set WSHShell = CreateObject("WScript.Shell")
Set appWord = CreateObject("Word.Application") ' Get a reference to the Word Application object.
appWord.Visible = TRUE ' Display the application.
appWord.Documents.Open(filename) ' Open a sample document.
Set appWord = Nothing
End Sub
</SCRIPT>

I pass in the path/filename. The path as I stated previously uses C://mypath/something/filename.txt.
If you have any spaces in your path, replace them with %20.

I do not know what the CreateObject would be for a text file but you can test it first in Word and see if it works.
 
Is it possibly a problem with the web server attempting to execute notepad in the context of IUSR_MachineName ???

That seems possible but I'd imagine you'd be getting a permission denied error.
 
theniteowl,

Thank you.
I think your code should be fine, but I guess we don't need
Set WSHShell = CreateObject("WScript.Shell")
Moreover, we cannot do something like
Set appNotePad = CreateObject("NotePad.Application")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top