|
-
Jan 31st, 2003, 12:40 AM
#1
how can I lock a file?
umm I don't want the user to be able to move/delete a certain file when my app is running. Is there a way to "lock" a certain file without having it opened?
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Jan 31st, 2003, 02:25 AM
#2
I don't think so not without having it opened.
-
Jan 31st, 2003, 04:57 AM
#3
Addicted Member
lock file
in VB6 you could open it as a random file, record length 1 character and LOCK #fn,1. Anyone who tries to access the file gets an error. CAN you do something similar in VB.NET ??
-
Jan 31st, 2003, 10:58 AM
#4
I wonder how many charact
Well, thats the same solution you would use in Vb.Net
http://www.vbwm.com/articles/builder...p?ArticleID=15
VB Code:
' attempts to open a file C:\TEST.TXT for read and write' access, and locks the file from other processes.
Dim filename As String = "C:\TEST.TXT"
Dim myFileStream As System.IO.FileStream
Try ' attempt to open the file myFileStream = New System.IO.FileStream(filename, _ System.IO.FileMode.Open, _ System.IO.FileAccess.ReadWrite, _ System.IO.FileShare.None)
Catch ' display an error to the user
MessageBox.Show("Could not open file. Make sure " & filename & "exists.")
Finally
If myFileStream.CanRead Then
' read from the file here
' close the file when you are done
myFileStream.Close()
End If
End Try
-
Jan 31st, 2003, 11:22 PM
#5
well yeah I can open the file... I just didnt know if I should leave the file open or not. Sounds like I have to leave it open in order to lock the file....
btw you used FileStream in your code and I always use StreamReader and StreamWriter. What's the big difference?
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Feb 1st, 2003, 12:31 AM
#6
Sleep mode
Originally posted by MrPolite
well yeah I can open the file... I just didnt know if I should leave the file open or not. Sounds like I have to leave it open in order to lock the file....
btw you used FileStream in your code and I always use StreamReader and StreamWriter. What's the big difference?
from Microsoft Documentation..
StreamReader
Implements a TextReader that reads characters from a byte stream in a particular encoding
StreamWriter
Implements a TextWriter for writing characters to a stream in a particular encoding.
-
Feb 1st, 2003, 12:46 AM
#7
Originally posted by pirate
from Microsoft Documentation..
hmm so it sounds like that they are for text files
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|