' 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 FunctionThis one takes care of retrying in case it doesn't work. You will also need to adjust to Exception section to fit yours.