Announcement

Collapse
No announcement yet.

Replacing Text

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Replacing Text

    Id like to use the replace method in classic ASP programmatically. The following code reads the text in the dbconnection.asp file and displays the text to the screen but doesnt actually change the text in the dbconnection.asp file. I know I can create a brand new file and enter the text I want. I can also use a utility. However, is it possible to actually replace the text in an already existing file? Also, is ASP.Net any better? Any recommendations programmatically speaking?

    Thanks,

    Robin
    *************************************************************************************

    Const ForReading = 1, ForWriting = 2, ForAppending = 8
    Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0

    Dim strFQDBConnectionFilePath

    Dim objFileTextStream

    Dim objFSO
    Dim objFile

    Dim strLine

    Dim objCmd
    Dim objConn


    strFQDBConnectionFilePath = c:\inetpub\wwwroot\test\ & "dbconnection.asp"

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.GetFile(strFQDBConnectionFilePath)

    Set objFileTextStream = objFile.OpenAsTextStream(ForReading,TristateUseDefault)

    Do While objFileTextStream.AtEndOfStream <> True
    strLine = objFileTextStream.ReadLine

    strLine = Replace(strLine, "ex_", "tst_")

    Response.Write strLine
    Response.Write "<BR>" + vbCrLf
    Loop

    objFileTextStream.Close
    Set objFileTextStream = Nothing

  • #2
    It would be in bad taste to do so. Moreso anonymous access to write to files should be prevented.
    www.shapemetrics.com
    Red GateSQL tools for DBA

    Comment

    Working...
    X