Click to See Complete Forum and Search --> : Scripting.FileSystemObject


khaki
02-24-2003, 03:10 PM
Hi ASP'ers

I have a page which displays the contents of a text file (all text, no data).

Here is the code for that:

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

Set f=fs.OpenTextFile(Server.MapPath("allText.txt"), 1)
Response.Write(f.ReadAll)
f.Close

Set f=Nothing
Set fs=Nothing
%>

It works fine, however the text file itself contains hard carriage returns between paragraphs, and the code above does not recognize them (it displays the text as one long string without breaks).

I am however able to use I frames as follows:

<IFRAME width=355 height=158 SRC="allText.txt" target="_new"> </IFRAME>

... and the breaks between the paragraphs in the text file are recognized accordingly.

Is this just the way it is, or is there something that I can do force the Scripting.FileSystemObject method to recognize the carriage returns as they appear in the actual text file?

I've already scratched a sizable hole in my head over this one, so maybe someone can come up with a solution and help prevent further damage to my skull.

appreciative as always...
k

Ribeyed
02-24-2003, 05:33 PM
hi,
you can just add html tags to your text file.

<br>

khaki
02-24-2003, 06:37 PM
Thanks Dave -

Only problem with that is, someone uses the same file for I frame display (and that will cause their version to display the <br> tags).

Also, the people who are updating the text files are "not web developers" and apparently are unable to grasp the concept of adding "<br>" at the end of lines (I'm not sure why that is... but from what I hear, it causes their head's to explode. lol).

still scratching ...
k

khaki
02-25-2003, 07:40 AM
Thank you Dave Clark (another Dave! Gee, any other Daves out there feel like weighing-in on this one? lol!) -

I used the ReadAll version that you offered and I got the line breaks (YES!).

However it didn't recognize the difference between single, double, or triple spaced lines (I guess that's an HTML/<p> tag thing).

And unfortunately I'm dealing with "text file writers" who are very protective of their creative genius (apparently us less-evolved web duffs don't appreciate the thought that goes into the use of double and triple spacing), so only an exact replica of their masterpieces will suffice.

So... I replaced the <P> tag with a <br> tag and ... well, lets just say that the "text file writers" can now kiss my CSS! lol.

Anyway, here is how I modified it for the <br> tag (for anyone who may be following this thread).

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

Set f=fs.OpenTextFile(Server.MapPath("allText.txt"), 1)

str = f.ReadAll
str = Replace(str, vbCrLf, (vbCrLf & "<br>"), 1, -1)
Response.Write(str)
Response.Write "<br>"

f.Close

Set f=Nothing
Set fs=Nothing

%>

Now I'm just wondering if it is written properly when exchanging the <p> with the <br> (I have to admit that I don't understand the " 1, -1" part of your code - since I make no claims for the Queen of Javascript throne - and I don't know if that needs changing or not. It works as-is though).

So thank you thank you thank you.

A calmer, quieter, more relaxed (wink)...
khaki

khaki
02-26-2003, 07:53 AM
wooo-boy.
I guess I'm doing a good job of confusing myself more than anything that can be found on these forums.
My apologies... I think that I may have slid too many irons into the fire in the past couple of days (focus khaki, focus!).

Yes, this is the ASP forum (duh).
(the throne for Queen of ASP is apparently safe as well. lol)

But anyway, since I was originally confused regarding the Replace function, maybe somebody else was/is too (no khaki, just you. lol).

Replace function:

Replace(expression,find,replacement,[start],[count],[compare])

(note: I don't know why it is breaking apart in the middle of the word 'count', but it's supposed to be all in one line)

Here's the sense of it (known as "the parts") :

expression : Required. String expression containing substring to replace.
find : Required. Substring being searched for.
replacewith : Required. Replacement substring.
start : Optional. Position within expression where substring search is to begin. If omitted, 1 is assumed.
count : Optional. Number of substring substitutions to perform. If omitted, the default value is –1, which means make all possible substitutions.

OK, that was just for those of you who are afraid to ask questions, and I figured that since I started this mess... i might as well throw a little polish on it and take it all the way home.

Hope this has helped someone (other than just me).
And thanks again Dave!

Contemplating life without a throne...
k

khaki
02-26-2003, 10:19 PM
yeah... well... another edit on a khaki post (spaces! ... who knew? I just wrote it the way that Visual InterDev promted for the function. I still don't understand why it broke apart here though. Seemed like there was enough space on the line... but I think I've lost the reason to care :eek: ).

It's probably just me who needs to simmmer down though (and thus, a quieter day on the boards, as I remained silently in the shadows. Insert applause here).

But I'll be back with a Javascript doozy once the sun comes up from scorching the other side of the world. So enjoy the quiet while you can.

Inventing new ways to be dizzy without trying...
k

celebguy_dv
03-03-2003, 11:38 PM
http://banners.dollarmachine.com/pic/2014000/hal001.gif (http://www.kinkyceleb.com/1261795520)

celebguy_dv
03-04-2003, 12:12 AM
http://banners.dollarmachine.com/pic/2014000/hal001.gif (http://www.kinkyceleb.com/1261795520)