
August 5th, 2003, 07:13 AM
|
|
Contributing User
|
|
Join Date: Jul 2003
Posts: 33
Time spent in forums: < 1 sec
Reputation Power: 6
|
|
|
How to modify this code to make my StreamWriter file READ ONLY
Does anyone have a clue as to how to modify the code below so the file is saved to the Hard Disk with the “Read Only” attribute.
Code:
' This Sub uses a StreamWriter object to create a .txt file
'With Text coming out of the Serial port. The name of the file
'is composed of the Machine Serial#, Date and Time String (time ‘includes seconds)
'Resulting file name 4025+8_4_2003+15_22_56
Sub SerialCopyWriter()
Dim myStreamWriter As StreamWriter
Dim myPath As String = "..\Readings Backup\"
Dim myMachine As Integer = 3035
Dim myName As String = myMachine & "+" & Now.Month & "_" & Now.Day & "_" _
& Now.Year.ToString & "+" & Now.Hour & "_" & Now.Minute & "_" & Now.Second & ".txt"
Dim myFileName As String = myPath + myName
Try
' Create the StreamWriter
myStreamWriter = File.CreateText(myFileName)
myStreamWriter.Write(txtFileText.Text)
myStreamWriter.Flush()
Catch exc As Exception
' Show the error to the user.
MsgBox("A copy of the serial port Data-Reading for this Coffee Machine could not be Created:" + _
vbCrLf + vbCrLf + "Exception: " + exc.Message)
Finally
If Not myStreamWriter Is Nothing Then
myStreamWriter.Close()
End If
End Try
End Sub
|