|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to lock a text file?Hi,everybody,
I will edit a text file and another user maybe read it via LAN at any time. I want to lock the text file(no reading and writing) while I am editting. Anyone can help me? Thanks in advance, Peter Peter wrote:
> I will edit a text file and another user maybe read it via LAN at any time. It depends on the method you will use to edit the file. If using> I want to lock the text file(no reading and writing) while I am editting. > Anyone can help me? something like a StreamReader or StreamWriter, then specify the appropriate sharing in the constructor. Can you give us more information on how you will be editing the file? Hi, Chris,
Thanks for you reply. I will write a text file like below: If System.IO.File.Exists("C:\Test.TXT") Then System.IO.File.Delete("C:\Test.TXT") Dim file1 as new System.IO.StreamWriter("C:\Test.TXT") file1.Writeline("Here is the first line.") file1.close Peter Peter wrote:
> If System.IO.File.Exists("C:\Test.TXT") Then I was incorrect in my other post. The StreamWriter constructor does> System.IO.File.Delete("C:\Test.TXT") > Dim file1 as new System.IO.StreamWriter("C:\Test.TXT") > file1.Writeline("Here is the first line.") > file1.close not have the sharing argument for the constructor. Instead, you should use the FileStream constructor in conjunction with the StreamReader: Dim fs As New FileStream("filename.ext", FileMode.Open, FileAccess.ReadWrite, FileShare.Read) Dim sw As New StreamWriter(fs) 'Work with stream writer here This file stream opens the file for Read/Write access and allows other processes to open the file for Read access only. I see, I should set the FileAccess and FileShare parameters for the
FileStream object. Thank you, Chris Peter
Combo Boxes in Datagrids
Experience Request: GPS Application What is the optimal way to upload 10,000 records to Oracle DB? Multi-dimensional array - Question on Data types How to debug program error on Windows with another language? Prompting for an IP address Tab groups in VB2003 debugging Connect to the right SQL Server during runtime Access DB on a pocket PC How can I get the data type of a data table's columns? |
|||||||||||||||||||||||