Answer» Hello,
I was running my vb.net when I got an error message saying that it could not read a file because it was being used by an other process, could anyone tell me the code to IGNORE anyfile that my program cannot read.
Here is the error message: System.IO.IOException:The processus was not able to acess this file "c:\pagefile.sys", because it is being used by an other process at System.IO.__Error.WinIOError(Int32 errorCode, String str) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize) at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize) at System.IO.StreamReader..ctor(String path) at CRC32VB.form1.btnCrc_Click(Object SENDER, EventArgs e) in C:\app\engine\Copie DE current\Form1.vb:line 281 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.WndProc(Message& m) at System.Windows.Forms.ControlNativeWindo w.OnMessage(Message& m) at System.Windows.Forms.ControlNativeWindo w.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callb ack(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Thanks
Al968Perhaps a Try/Catch sequence would help; On the Try side, you can attempt to read a file, if an exception is THROWN, you can Catch it with the EX exception and write code on what to do if the file is not accessible.
8-)I don't know how to do that but I did think exactly the same thing. Would you know of an artcile that explains how to do that ?
Thanks
Al968Google is very good at finding things:
Try/Catch
More Try/Catch
These should explain what you need. Also the supplied help with Visual Studio or Visual Basic .Net is invaluable if not sometimes overwhelming.
Happy Programming 8-)
Thanks A lot
Very helpful
Al968I've tried it however I still get the error message but not as often, here is the code I puted in:
'Try and catch Try SearchString = "a" If str.IndexOf(SearchString) <> -1 Then vir = "a" Catch ex As Exception MsgBox(ex.Message) End Try Thanks
Al968Quote I was running my vb.net when I got an error message saying that it could not read a file because it was being used by an other process There is not enough code posted to see the problem, but the try/catch construct is for the file read.
pseudocode:
Try read the file (you will need other parameters depending on what type of read this is...database, flat file, random read) Catch EX as Exception code this piece of what to do if the read fails End Try
Good luck. 8-)
PS. Did you read the links that were posted?Yes I did and they were useful thats how I came up with the code in my previous POST. Isn't the pseudocode exactly what I have ?
Thanks
Al968
|