SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Posts rarely lloydi's Avatar
    Join Date
    Jan 2002
    Location
    Swindon UK
    Posts
    620
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simpleton requires help re creating a .csv file

    OK, I know how to use ASP to create and write into a .CSV file on the server, but I have a small problem. Every time I write to the file I am adding new lines each time. I don't know how to wipe the previous contents out, and I thought this is probably a no-brainer for you guys ...

    So, I'm looking either to delete the file at the start of the process and start from scratch or

    * open the file
    * wipe all contents from file
    * write to the newly cleaned file

    Hope someone can help.
    Build Your Own Web Site the Right Way!
    A beginners' HTML/CSS book with web standards at its heart
    The Ultimate HTML Reference
    A complete reference, in glorious hardback

  2. #2
    SitePoint Addict
    Join Date
    Mar 2002
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Instaed of opening the file, create a new one irrespective as to whether it already exists which will wipe it clean. Hope this helps.

    Nick
    All4YourPC for all your PC needs. Custom software.
    Websites. Web marketing. Training.
    http://members.aol.com/nickjc67

  3. #3
    Posts rarely lloydi's Avatar
    Join Date
    Jan 2002
    Location
    Swindon UK
    Posts
    620
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by nickc
    Instaed of opening the file, create a new one irrespective as to whether it already exists which will wipe it clean. Hope this helps.

    Nick
    Actually, I thought that was what I was doing. Here's what I have:

    <%
    Set fs = Server.CreateObject("Scripting.FileSystemObject")
    Set a = fs.OpenTextFile(server.MapPath(/data/data.csv"),8, true)
    strCSV = replace (strCSV,"<br />",chr(13))
    a.WriteLine(strCSV)
    %>
    Build Your Own Web Site the Right Way!
    A beginners' HTML/CSS book with web standards at its heart
    The Ultimate HTML Reference
    A complete reference, in glorious hardback

  4. #4
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is a perfect example of why you should use enumerated constants instead of values.

    Here's the offending line with the relevant value replaced with the corresponding enumerated constant.... get it now?:
    Code:
    Set a = fs.OpenTextFile(server.MapPath(/data/data.csv" ),ForAppending, true)
    For more info (i.e. the value you need for writing WITHOUT appending) consult your scripting documentation...

    hint hint
    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!


Bookmarks

Posting Permissions

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