Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

process problem

Status
Not open for further replies.

curiousvbnet

Programmer
Apr 6, 2007
40
FR
Hi,

I have created a sub to export a treeview called 'TreeView1' to a txt file.
A user can use the part of the treeview he wants to export by checking node(s)

The problem is that when i export once the nodes the user has checked( it works correctly), if after i want to export others nodes, i receive this message

[blue]a SystemIo.IoException occured in mscorlib.dll.
The process can not reach the file C:\export_test.txt because it is already in use by another process' [/blue]

The file C:\export_test.txt is the same i used before for the first export .

The clsWriter variable is private and also the OutputPath variable

Thanks really a lot for all your precious help.
Best regards.
Nathalie

Here is my sub code


Code:
[blue]Private Sub Export_Partie_TreeView_ToTxt[/blue](ByVal TreeView As TreeView) ', ByVal OutputPath As String) 
        Dim clsOutStream As New System.IO.MemoryStream 
        Dim clsPrompt As New SaveFileDialog 
        clsPrompt.Title = "Sélection d'un fichier d'export" 
        clsPrompt.Filter = "Text Files {*.txt}/*.txt" 
                If clsPrompt.ShowDialog(Me) = Windows.Forms.DialogResult.OK Then 
            OutputPath = clsPrompt.FileName 
        ElseIf clsPrompt.ShowDialog(Me) = Windows.Forms.DialogResult.Cancel Then 
            Exit Sub 
                End If 
 clsWriter = New System.IO.StreamWriter(OutputPath) [red]<- at this level the program stops and i receive the message above [/red]
     
        
            [blue] ExportToText2(TreeView1.Nodes, 0) [/blue]
       [green] 'close stream... [/green]
        clsOutStream.Flush() 
        clsOutStream.Close() 
        
        System.Diagnostics.Process.Start(OutputPath) 
                OutputPath = Nothing 


    End Sub

Code:
 Private Sub ExportToText2(ByVal Nodes As TreeNodeCollection, ByVal Indentation As Integer) ', ByVal OutStream As System.IO.MemoryStream) 
        Dim clsOutStream As New System.IO.MemoryStream 
        Dim clsNode As TreeNode 


       
        For Each clsNode In Nodes If clsNode.Checked = True Then 
                clsWriter.WriteLine(New String(" "c, Indentation * 4) & " - " & clsNode.Text) 
                                ExportToText3(clsNode.Nodes, Indentation + 1) 

                clsWriter.Flush() 
                clsWriter = Nothing 


                         End If 

        Next 
    End Sub
Code:
[blue]Private Sub ExportToText3[/blue](ByVal Nodes As TreeNodeCollection, ByVal Indentation As Integer) 
        Dim cls2Node As TreeNode 


        
        For Each cls2Node In Nodes 
            clsWriter.WriteLine(New String(" "c, Indentation * 4) & " - " & cls2Node.Text) 

            ExportToText3(cls2Node.Nodes, Indentation + 1) 
            clsWriter.Flush() 
        Next 
    End Sub


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top