Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    Brighton, UK
    Posts
    282
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Server.CreateObject File already exists problem

    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
    <marquee>thanks</marquee>

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    Code:
    <%
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •