Print Page | Close Window

Scripting.FileSystemObject filename prob

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=10458
Printed Date: 31 March 2026 at 4:19pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Scripting.FileSystemObject filename prob
Posted By: Nathan
Subject: Scripting.FileSystemObject filename prob
Date Posted: 16 May 2004 at 6:11am

I am using

Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

to write asp files to my server (exporting posts from my Forum)

The code works fine, but if the strsubject (which is used for the file name) is for example: 'Walking on Corfu' instead of saving the file as: walking on corfu.asp

it changes it to:

walking &#111n corfu.asp

(whenever the file name contains the letters 'on', then they are replaced with &#111n )

How can I stop this happening?

Thanks for any help you can offer.

 

Nathan

Sample code as follows:

 

Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

path = server.MapPath("posts/"& strsubject &".asp")
'illegal chars are then stripped out of the path file name
Set objTextStream = objFSO.OpenTextFile(path, fsoForWriting, True)

objTextStream.WriteLine "<html>"
objTextStream.WriteLine "<head>"

etc etc etc

objTextStream.Close

 

 




Replies:
Posted By: Semikolon
Date Posted: 16 May 2004 at 6:45am
because on can be used to post malicious code, so WWF replaces on with &#111;n

I'm not sure what file the functon is in but it is in one of the files in the functions folder


Posted By: Mart
Date Posted: 16 May 2004 at 7:01am
He's not talking about WWF It's a custom script...


Posted By: Semikolon
Date Posted: 16 May 2004 at 7:44am
yeah, but I think he saves the topics to files and then he uses the same page as WWF uses to save to the database


Posted By: Nathan
Date Posted: 16 May 2004 at 10:18am

Thanks very much for your help so far.

Correct this is a custom script, but I have written a short bit of code to access the Forum SQL database in order to extract the Thread Subject title. For example:

 'Get the threads from the database
 'Create a record set object to the Threads held in the database
 Set rsThread = Server.CreateObject("ADODB.Recordset")

 'Initalise the strSQL variable with an SQL statement to query the database get the thread details

 strSQL = "EXECUTE wwfSpThreadDetails @lngTopicID = " & lngTopicID


 'Set the cursor type property of the record set to dynamic so we can naviagate through the record set
 rsThread.CursorType = 1

 'Query the database
 rsThread.Open strSQL, strCon 
  'Read in the thread subject forum ID and where the topic is locked
  strSubject = rsThread("Subject")
 
 
This strSubject string is then being used as the file name.

Nathan

 



Posted By: Semikolon
Date Posted: 16 May 2004 at 12:09pm
you have to do a reverse replace of the words that are beiing replaced before inserted into the database


Posted By: Nathan
Date Posted: 19 May 2004 at 2:27pm

Fantasic. That's cured it - thanks very much.

Incidentally, you maybe interested in seeing the finished (badly written) code. Basically, it will export all of my forum threads to asp files, but with correct TITLE and META tags. The idea for this, is that I use the site search script (from Bruce), and now my site users can search my site pages and my forum threads at the same time - as they have been exported!  Works a treat and my users (and hopeful Google) love it!

http://www.agni.gr - www.agni.gr

thanks again for your help. Beers are on me if you happen to pop by.

Nathan

<!--#include file="common.asp" -->
<!--#include file="date_time_functions.inc" -->
<!--#include file="langauge_file.inc" -->
<!--#include file="forum_permissions.inc" -->

 


<%

 


Response.Buffer = True

'Dimension variables
Dim rsForum    'Holds the Database Recordset Variable for the topic details
Dim rsThread   'Holds the database recordset variable for the thread
Dim intForumID   'Holds the forum ID number
Dim strForumName  'Holds the forum name
'Dim lngTopicID   'Holds the topic number
Dim strSubject   'Holds the topic subject
Dim strUsername   'Holds the Username of the thread
Dim lngUserID   'Holds the ID number of the user
Dim dtmTopicDate  'Holds the date the thread was made
Dim strMessage   'Holds the message body of the thread
Dim lngMessageID  'Holds the message ID number
Dim strAuthorHomepage  'Holds the homepage of the Username if it is given
Dim strAuthorLocation  'Holds the location of the user if given
Dim strAuthorAvatar  'Holds the authors avatar 
Dim strAuthorSignature  'Holds the authors signature
Dim lngAuthorNumOfPosts  'Holds the number of posts the user has made to the forum
Dim dtmAuthorRegistration 'Holds the registration date of the user
Dim lngNumberOfViews  'Holds the number of times the topic has been viewed to save back to the database
Dim intStatus   'Holds the users interger status
Dim strStatus   'Holds the users status
Dim strMode   'Holds the mode of the page that is being passed
Dim intTopicPageNumber  'Holds the topic page position to link back to
Dim blnNoThread   'Set to true if there is no thread to view
Dim blnIsModerator  'Set to true if the user who posted the message is a forum moderator
Dim blnForumLocked  'Set to true if the forum is locked
Dim blnTopicLocked  'set to true if the topic is locked
Dim intThreadNo   'Holds the number of threads in the topic
Dim intPriority   'Holds the priority level of the topic
Dim strPostPage   'Holds the page the form is posted to
Dim intRecordPositionPageNum 'Holds the recorset page number to show the Threads for
Dim intTotalNumOfPages  'Holds the number of pages
Dim intRecordLoopCounter 'Holds the loop counter numeber
Dim intThreadPageLoopCounter 'Loop counter for other thread page link
Dim intTotalNumOfThreads 'Holds the total number of therads in this topic
Dim strAuthorIP   'Holds the authors IP
Dim strSearchKeywords  'Holds the keywords to search for
Dim sarySearchWord  'Array to hold the search words
Dim intHighlightLoopCounter 'Loop counter to loop through words and hightlight them


Dim poststext


 Const fsoForWriting = 2
 
 
dim path


 dim body, head
 dim textformat

 Dim title

 

for lngTopicID = 2000 to 2121

 'Get the threads from the database
 'Create a record set object to the Threads held in the database
 Set rsThread = Server.CreateObject("ADODB.Recordset")

 'Initalise the strSQL variable with an SQL statement to query the database get the thread details

 strSQL = "EXECUTE wwfSpThreadDetails @lngTopicID = " & lngTopicID


 'Set the cursor type property of the record set to dynamic so we can naviagate through the record set
 rsThread.CursorType = 1

 'Query the database
 rsThread.Open strSQL, strCon


 'If there is no topic in the database then display the appropraite mesasage
 If rsThread.EOF Then
 
  'If there are no thread's to display then display the appropriate error message
  strSubject = strTxtNoThreads


 'Else there are records returned by the database
 Else


  'Read in the thread subject forum ID and where the topic is locked
  strSubject = rsThread("Subject")
 
 
 End If

 

 

if not strSubject = strTxtNoThreads then
 
 Response.Write strSubject
 Response.Write "<BR>"

 Dim objFSO
 
 Dim objTextStream
 
 Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
 strsubject = Replace(strsubject, "?", " ", 1, -1, 1)
 strsubject = Replace(strsubject, ",", " ", 1, -1, 1)
 strsubject = Replace(strsubject, "\", " ", 1, -1, 1)
 strsubject = Replace(strsubject, "/", " ", 1, -1, 1)
 strsubject = Replace(strsubject, "'", " ", 1, -1, 1)
 strsubject = Replace(strsubject, ":", " ", 1, -1, 1)

 strsubject = Replace(strsubject, "&#111;", "o", 1, -1, 1)
 strsubject = Replace(strsubject, "&#146;", "", 1, -1, 1)
 strsubject = Replace(strsubject, "&#079;", "o", 1, -1, 1)

 path = server.MapPath("posts/"& strsubject &" - Corfu Post.asp")
 path = Replace(path, " ", "_", 1, -1, 1)
 
 Response.Write lngTopicID & " "
 Response.Write path
 Response.Write "<BR>"
 Response.Write "<BR>"

 Set objTextStream = objFSO.OpenTextFile(path, fsoForWriting, True)

 head = "<" & "%" & "Option Explicit" &  "%" & ">"

 

 title = strSubject & " Corfu Travel Guide Discussion Forum"
 title = Replace(title, " ", ",", 1, -1, 1)


 body="<!--#include virtual=" & "/message_boards/display_topic_threads2.asp" & " -->"
 


 'Display the contents of the text file
 objTextStream.WriteLine head
 objTextStream.WriteLine "<" & "%"
 objTextStream.WriteLine

 

 objTextStream.WriteLine "Dim lngTopicID"
 objTextStream.WriteLine "lngTopicID = " & lngTopicID

 objTextStream.WriteLine "%" & ">"

 objTextStream.WriteLine
 objTextStream.WriteLine "<html>"
 objTextStream.WriteLine "<head>"

 objTextStream.WriteLine "<title>" & strSubject & " - Corfu Travel Guide Discussion Forum </title>"
 objTextStream.WriteLine "<meta name=""keywords"" content=""" & title & """>"
 objTextStream.WriteLine "<meta name=""description"" content=""Corfu Forum Post - " & strSubject & """>"

 

 objTextStream.WriteLine "<meta http-equiv=""Cache-Control"" content=""no-cache"">"
 objTextStream.WriteLine "<meta name=""generator"" content=""Taverna Agni and Agni Travel - Corfu"">"
 objTextStream.WriteLine "<meta name=""revisit-after"" content=""3



Posted By: Semikolon
Date Posted: 20 May 2004 at 6:36am

sory, I don't drink beer!

 

I didn't read through the code either.. too much



Posted By: Sxar
Date Posted: 20 May 2004 at 9:32am

Funny bit of FrontPage code down the bottom.

FrontPage is a very dirty program...



Posted By: dpyers
Date Posted: 20 May 2004 at 11:42am
Actually FP2003 is pretty clean. Let's you turn off all of the "helpful" tidbits and do pretty much straight coding with your own formatting rules.

-------------

Lead me not into temptation... I know the short cut, follow me.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net