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?
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.....
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.
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 = fspenTextFile(filePath,2)
txtS.Write(s)
txtS.close
response.write "(File saved in " & filePath &".)"
Set Shell =CreateObject("WScript.Shell")
Shell.Run "Notepad " & filePath
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.
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")
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.