Livi17
Livi17

Reputation: 1660

.txt embed in .asp file

I'm new to ASP and having a little trouble.

A CMS is pushing out data into .txt files. I do not have the option to change what the CMS outputs, so they have to be .txt files.

a text file named textfile.txt looks like this:

widetxt=<P align='left'><B>Hello world!</B></P>&done=1

I need to display the "widetxt" variable on an .asp page.

The directory structure is like this:

ASP file is at the root of a folder, textfile.txt is located in a folder named "txt" off of the root folder.

index.asp
[txt]
  |----textfile.txt

I tried the below code in the asp file, but I get a 500 error: "500 - Internal server error. There is a problem with the resource you are looking for, and it cannot be displayed."

<%
Set fs = CreateObject("Scripting.FileSystemObject")

Set wfile = fs.OpenTextFile(Server.MapPath("txt/textfile.txt"),1,true))
filecontent = wfile.ReadAll

wfile.close
Set wfile=nothing
Set fs=nothing

response.write(filecontent)
%>

I know for a fact both files are on the server and are where they are supposed to be.

If i remove the above code, and just put:

<%
response.write("Hello World!")
%>

the asp file works. So something in the OpenTextFile code is wrong, but i do not have the experience to know what it is.

Any help would be appreciated.

Upvotes: 0

Views: 482

Answers (1)

RogueSpear00
RogueSpear00

Reputation: 619

Set wfile = fs.OpenTextFile(Server.MapPath("txt/textfile.txt"),1,true))

You have one too many ) at the end of this statement. Every ( should have a matching ).

Set wfile = fs.OpenTextFile(Server.MapPath("txt/AttachmentFix.txt"),1,true)

Also, I don't see the remainder of your code, but after your response.write(filecontent) make sure to set filecontent as Nothing.

Set filecontent = Nothing

Also, when you're developing in Classic ASP @jsobo is right - you should have Friendly Error messages disabled as you can see what errors the script is throwing back.

Upvotes: 1

Related Questions