> ' File to string > Public Function FileToString() As Boolean > Dim lcFile As String = "" > Dim llSuccess As Boolean = False > Dim lnCounter As Integer = 0 > Dim lnDelay As Integer = 500 > Dim lnRetry As Integer = 8 > Dim loFile As IO.StreamReader > > ' Reset the values > cMessage = "" > cString = "" > > ' Initialization > lcFile = Trim(cFile) > > For lnCounter = 1 To lnRetry > > Try > loFile = New IO.StreamReader(lcFile, True) > cString = loFile.ReadToEnd() > loFile.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 > > cMessage = loError.Message > End Try > > Next > > ' Reset the values > cFile = "" > > Return llSuccess > End Function > > ' Same as FileToString() but for binary files > ' This is used when you want to take a JPG, for example, and encode it as Base64 into a XSL > Public Function FileToStringBinary() As Boolean > Dim lcFile As String = "" > Dim llSuccess As Boolean = False > Dim lnCounter As Integer = 0 > Dim lnDelay As Integer = 500 > Dim lnRetry As Integer = 8 > Dim loFile As IO.StreamReader > > ' Reset the values > cMessage = "" > cString = "" > > ' Initialization > lcFile = Trim(cFile) > > For lnCounter = 1 To lnRetry > > Try > loFile = New IO.StreamReader(lcFile, System.Text.Encoding.Default) > cString = loFile.ReadToEnd() > loFile.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 > > cMessage = loError.Message > End Try > > Next > > ' Reset the values > cFile = "" > > Return llSuccess > End Function >>