Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Recommendation on accessing a file
Message
From
21/09/2006 20:17:44
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
21/09/2006 20:10:55
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
VB 8.0
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01156238
Message ID:
01156240
Views:
21
This message has been marked as the solution to the initial question of the thread.
>This message might be returned as an error:
>
>"The process cannot access the file 'D:\iis\Direct Martial Arts\BannerRight3.html' because it is being used by another process."
>
>when the VB.NET application is trying to access BannerRight3.html at the same time the robot application is storing it on the drive. This is done every minute. So, there could be a collision.
>
>This is the method that triggers it:
>
>
>        ' FileToStr() VFP equivalent
>        ' expC1 File name
>        Public Function FileToStr(ByVal tcFileName As String) As String
>            Dim lcString As String = ""
>            Dim loFile As IO.StreamReader
>            Try
>                loFile = New IO.StreamReader(tcFileName, True)
>                lcString = loFile.ReadToEnd()
>                loFile.Close()
>            Catch loError As Exception
>
>                ' Get the proper definition as per the current scope
>                If oProcess Is Nothing Then
>                    oApp.ErrorSetup(loError)
>                Else
>                    oProcess.ErrorSetup(loError)
>                End If
>
>            End Try
>            Return lcString
>        End Function
>
>
>I was wondering if there could be a good mechanism to have this FileToStr() method to retry or wait or something like that which would make it more solid. Basically, I wouldn't want to retry indefinitely. Maybe just one or two seconds. But, before using that approach, I was wondering if there would be something in regards to the StreamReader() that could help me.

You could put try...catch in a loop w/o throwing the error. At the end of the loop if loFile is null throw.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform