Announcement

Collapse
No announcement yet.

Example of writing to a file

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

  • DJF3
    replied
    Thanks,
    With your help I have been able to create the following code that writes text to a file:

    Code:
    Imports System.IO
    Imports System.IO.StreamReader 
    
    Sub Main(ByVal varParameters)
    
        Const strDebug = 1
        Const strFilename = "C:\Program Files\HomeSeer 2\data\DJ\ftpthis.txt"
    
        If File.Exists(strFilename) then File.Delete(strFilename)
        PrintToFile(strFilename,"my string written to file")
    
    End Sub
    
    
    Function PrintToFile(strFilename,msg)
            Dim oSW As StreamWriter
            oSW = File.AppendText(strFilename.ToString())
            oSW.WriteLine(msg)
            oSW.Close()
    End Function
    (haven't tested the exact code above yet because it's part of a bigger script that now works - which I will soon share with you)

    Leave a comment:


  • jon00
    replied
    These are one liners:

    To append to an existing file:

    PHP Code:
    My.Computer.FileSystem.WriteAllText(filepath,textstring,True
    To overwrite a file:

    PHP Code:
    My.Computer.FileSystem.WriteAllText(filepath,textstring,False

    Leave a comment:


  • Rupp
    replied
    Here's a .net sub to write to a log file

    Code:
    Public Sub PrintToFile(ByVal msg)
            Dim oSW As StreamWriter
            oSW = File.AppendText(Server.MapPath(ConfigurationManager.AppSettings("LogFile").ToString()))
    
            oSW.WriteLine(msg)
            oSW.Close()
       End Sub
    Just change Server.MapPath(ConfigurationManager.AppSettings("LogFile").T oString()) to the path of the output file.

    Leave a comment:


  • DJF3
    started a topic Example of writing to a file

    Example of writing to a file

    Team,

    Can anyone share some working sample .vb code that writes text to a new or existing file?

    I have done this on IIS before but it doesn't run on the HS webserver.

    Thank you!
    DJ
    Last edited by DJF3; January 4, 2010, 04:20 AM.
Working...
X