Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Is there function like strtofile() in .NET framework?
Message
 
 
To
19/02/2008 19:28:33
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
C# 2.0
Miscellaneous
Thread ID:
01294090
Message ID:
01294093
Views:
26
>>I want to log error information into a text file. In VFP I would do it with a simple STRTOFILE() function. Is there something like that in .NET?
>
>This is what I use to create a file from a string:
>
>
>        ' Create a file
>        ' expC1 String
>        ' expC2 File
>        Public Function CreateFile(ByVal tcString As String, ByVal tcFile As String) As Boolean
>            Dim llSuccess As Boolean = False
>            Dim lnCounter As Integer = 0
>            Dim lnDelay As Integer = 250
>            Dim lnRetry As Integer = 8
>            Dim loFileStream As FileStream
>            Dim loStreamWriter As IO.StreamWriter
>            For lnCounter = 1 To lnRetry
>                Try
>                    loFileStream = New FileStream(tcFile, FileMode.Create)
>                    loStreamWriter = New StreamWriter(loFileStream, System.Text.Encoding.Default)
>                    loStreamWriter.Write(tcString)
>                    loStreamWriter.Close()
>                    loFileStream.Close()
>                    llSuccess = True
>                    Exit For
>                Catch loError As Exception
>
>                    ' If we have not reached the maximum tries of 8, we retry
>                    If lnCounter < 8 Then
>
>                        ' Wait for a timeout before retrying
>                        System.Threading.Thread.Sleep(lnDelay)
>
>                        Continue For
>                    End If
>
>                    ' 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
>            Next
>            Return llSuccess
>        End Function
>
>
>This one takes care of retrying in case it doesn't work. You will also need to adjust to Exception section to fit yours.

Thank you, Michel. I will just need to translate your code into C#.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Reply
Map
View

Click here to load this message in the networking platform