Forums

ASP

This topic is locked

help needed with script for creating folder etc.

Posted 29 Nov 2006 12:16:45
1
has voted
29 Nov 2006 12:16:45 Leigh Mainprize posted:
Hi,

Can anyone help me with ASP code for creating a folder and text file when a new listing is added to my database.

I've created a script which adds a new record to the DB, but I now need it to create a new folder and new test file each and every time a new record is added.

hope someone can help

Replies

Replied 05 Dec 2006 12:04:03
05 Dec 2006 12:04:03 Lee Diggins replied:
Hi Leigh

First your IIS account needs to have write permissions on the folder you wish to create the subfolders and text files.

Next you need to be trying to use the FileSystemObject:

<%
Dim strFolderName
Dim strFileName
Dim strPath

strFolderName = "myFolder"
strFileName = "myFile"

strPath = "C:\myPath"
'or you can use the Server.MapPath method comment out the line you don't want
strPath = Server.MapPath("/myPath/"

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

If Not objFSO.FolderExists(strPath) The
objFSO.CreateFolder(strPath & strFolderName)

Dim objTextStream

'three parameters
'1 = file path and name
'2 = overwrite [true|false]
'3 = unicode [true|false]
Set objTextStream = objFSO.CreatTextFile(strPath & strFolderName & strFileName, true, false)
objTextStream.Write("Some test text"

objTextStream.Close
Set objTextStream = Nothing
Else
Response.Write("Folder Already Exists"
End If

objFSO.Close
Set objFSO = Nothing

%>

Should give you a start.

Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
<b>Lee Diggins</b> - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>

Reply to this topic