...

View Full Version : Server.CreateObject File already exists problem



chris_angell
01-08-2008, 01:24 PM
hello i am creating a xml file using ASP dynamically and when i run the script it works first time and creates the file

but

when the file already exists it creates and error and doesn't write over the previous file.. i am trying to make an admin area where this file can be constanly updated ??

has anyone got any ideas why i can't write over the preious file or any ideas how i can get round this..

here is my code

FmContent = "folder"

dim fs,f
set fs=Server.CreateObject("Scripting.FileSystemObject")
f=fs.CreateFolder(Server.MapPath("" & FmContent & ""))
set f=nothing
set fs=nothing

CSVTxt = "<?xml version=""1.0"" encoding=""utf-8"" ?>" & vbcrlf & _
"<Artists>" & vbcrlf & _
"<Artists>" & vbcrlf & _
"</Artists>"

AddHtm = "file"
Set fsoObject = Server.CreateObject("Scripting.FileSystemObject")
Set tsObject = fsoObject.CreateTextFile(Server.MapPath("" & FmContent & "/" & AddHtm & ".xml"))
tsObject.Write CStr(CSVTxt)

Set fsoObject = Nothing
Set tsObject = Nothing
%>


many thanks chris

Spudhead
01-08-2008, 04:23 PM
<%
dim FmContent, FmContent_path, CSVTxt, fs,f, tsObject, tsObject_path, AddHtm

FmContent = "folder"
FmContent_path = Server.MapPath(FmContent)

CSVTxt = "<?xml version=""1.0"" encoding=""utf-8"" ?>" & vbcrlf & _
"<Artists>" & vbcrlf & _
"<Artists>" & vbcrlf & _
"</Artists>"

AddHtm = "file"

set fs=Server.CreateObject("Scripting.FileSystemObject")

if not fs.FolderExists(FmContent_path) then
set f = fs.CreateFolder(Server.MapPath(FmContent))
set f = nothing
end if

tsObject_path = FmContent_path & "/" & AddHtm & ".xml"

set tsObject = fsoObject.CreateTextFile(tsObject_path)
tsObject.Write CSVTxt
set tsObject = nothing

set fs=nothing
%>

It's CreateFolder that errors if the folder already exists, not CreateTextFile. And you had some funny syntax thing going on with your MapPath variables - you don't need to wrap them in quotes.

HTH



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum