DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2004
    Posts
    2

    Thumbs up Write and read text file in asp

    Hi every one,

    I have some problem to write and read text file using asp.
    I used this code below which is got from this web site. When i run it, it does not show any error. But There is no text file created in C Drive.

    what is the error here, please let me know?

    ...................................................................
    <%
    function WriteToFile(FileName, Contents, Append)
    on error resume next

    if Append = true then
    iMode = 8
    else
    iMode = 2
    end if
    set oFs = server.createobject("Scripting.FileSystemObject")
    set oTextFile = oFs.OpenTextFile(FileName, iMode, True)
    oTextFile.Write Contents
    oTextFile.Close
    set oTextFile = nothing
    set oFS = nothing

    end function

    %>

    <HTML>
    <BODY>

    <%

    WriteToFile "C:\Test1.txt", "Hello How are you", True
    WriteToFile "C:\Test2.txt", "Hello How are you", false
    WriteToFile "C:\Test1.txt", chr(13) & chr(10) & "I am fine", true
    WriteToFile "C:\Test2.txt", chr(13) & chr(10) & "I am fine", false
    'Test1.txt contains:
    'Hello How are you
    'I am fine

    'Test2.text contains:

    'I am fine
    %>
    Write to File test is complete
    </BODY>
    </HTML>
    .....................................................

  2. #2
    Join Date
    Dec 2003
    Posts
    2,750
    I would comment out the line "on error resume next" and then load the page. I would be willing to bet you get an error, probably a permissions error.
    Paul
    ~~~~
    Microsoft MVP (Visual Basic)

  3. #3
    Join Date
    Dec 2004
    Posts
    2

    Correction

    I am seeking whatever correction to be solved.

  4. #4
    Join Date
    Dec 2003
    Posts
    2,750
    I don't think I understand your response. Do you encounter an error after removing the line "on error resume next"?

    Unless you remove this line of code no runtime errors will be raised. The code will simply resume after an error and you will never know whether an error has occurred.
    Paul
    ~~~~
    Microsoft MVP (Visual Basic)

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
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links