0

i am getting this problem in some systems, some systems working properly, here my code is,

Dim fileName As String = "FaultTypesByMonth.csv"  
        Using writer As IO.StreamWriter = New IO.StreamWriter(fileName, True, System.Text.Encoding.Default)     '------------  rao new ----

            Dim Str As String
            Dim i As Integer
            Dim j As Integer           
            Dim headertext1(rsTerms.Columns.Count) As String
            Dim k As Integer = 0
            Dim arrcols As String = Nothing
            For Each column As DataColumn In TempTab.Columns

                arrcols += column.ColumnName.ToString() + ","c
                k += 1
            Next

            writer.WriteLine(arrcols)          

            For i = 0 To (TempTab.Rows.Count - 1)
                For j = 0 To (TempTab.Columns.Count - 1)

                    If j = (TempTab.Columns.Count - 1) Then
                        Str = (TempTab.Rows(i)(j).ToString)
                    Else
                        Str = (TempTab.Rows(i)(j).ToString & ",")
                    End If                    
                    writer.Write(Str)       
                Next               
                writer.WriteLine()
            Next          
            writer.Close()
            writer.Dispose()
        End Using                  

        Dim FileToDelete As String = Nothing
        Dim sd As New SaveFileDialog
        sd.Filter = "CSV Files (*.csv)|*.csv"
        sd.FileName = "FaultTypesByMonth"
        If sd.ShowDialog = Windows.Forms.DialogResult.OK Then            
            FileCopy(fileName, sd.FileName)               
            MsgBox(" File Saved in selected path")
            FileToDelete = fileName
            If System.IO.File.Exists(FileToDelete) = True Then
                System.IO.File.Delete(FileToDelete)
            End If           
        End If
        FileToDelete = fileName
        If System.IO.File.Exists(FileToDelete) = True Then
            System.IO.File.Delete(FileToDelete)
        End If

when i am trying to save this file in desired path, then i am getting this error. if save in shared folder i am not getting this error

system.io.ioexception the process cannot access because it is being used by another process...

what i am doing wrong,Help me

Kariveda
  • 31
  • 4
  • Do you have write permission in that folder? – Jade Jun 03 '14 at 11:10
  • `FileCopy(fileName, sd.FileName)` you're calling a function. i can't see code for that function. also, you haven't stated on which line the error occurs. i'm assuming it occurs after this line. plus this is a duplicate of: http://stackoverflow.com/questions/24000704/the-process-cannot-access-the-file-xxxxxx-because-it-is-being-used-by-another-pr or maybe not a direct duplicate, but just as poor a question. – porkchop Jun 03 '14 at 14:41
  • hi, this fileCopy() is part of Microsoft.VisualBasic.FileSystem, i didn't write any function. And also some PC's this error is not getting. The error occuring only when try to save in C: drive only, not in any other Paths. I have to close or dispose this Stream to release the memory, i did it in the code. but still getting the error. – Kariveda Jun 04 '14 at 03:43

0 Answers0