Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Is there function like strtofile() in .NET framework?
Message
De
19/02/2008 19:28:33
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
C# 2.0
Divers
Thread ID:
01294090
Message ID:
01294092
Vues:
45
This message has been marked as the solution to the initial question of the thread.
>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.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform