StreamWriter...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • john20
    New Member
    • Jul 2008
    • 37

    StreamWriter...

    Hi All,

    I want to create StreamWriter object in shared.write mode

    i am writing below code to create an object .

    Dim objSW As StreamWriter = New StreamWriter(sE xportFolder & "\" & sSession & ".CSV")

    how can i create in shared mode.

    like we can do in FileStream i.e. fi.open("ADC",f i.read,fi.files hare.write)

    Thanks in advance

    -john
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    Create the FileStream first, and then create the StreamWriter from the FileStream.

    example
    Code:
    Dim fs as new FileStream(whateverYouNeedHere)
    Dim sw as new StreamWriter(fs)

    Comment

    • joedeene
      Contributor
      • Jul 2008
      • 579

      #3
      i dont really understand what you want to do, but no i dont believe you can open a streamwriter in shared mode, or something, but you can combine those in a way to be useful,

      example:

      Code:
      Private Sub btnWrite_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWrite.Click
                   writer()
          End Sub
      
      Private Sub writer()
              Dim filestream As New FileStream("C:\Test.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Write)
              Dim mynewstreamwriter As New StreamWriter(filestream)
              mynewstreamwriter.WriteLine("I Think This Will Work...")
              mynewstreamwriter.Flush()
              mynewstreamwriter.Close()
              filestream.Close()
          End Sub
      because all the streamwriter does, well is self-explanatory, it writes to a stream. and the io.filestream is just a stream that you can change and/or set options and permissions for. so you can combine them both to do something like that. but im not really an expert, so im not 100% sure, but when i tried it, it did create a text file with the text...

      Comment

      Working...