Bonjour,

J'ai un problème avec le code suivant :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 
        'ENREGISTREMENT DU FICHIER EN LOCAL
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        Dim pathBalance As String = System.Configuration.ConfigurationManager.AppSettings("balance")
 
        '1. Si le répertoire de base n'existe pas on le crée
        If Not System.IO.Directory.Exists(pathBalance) Then
            System.IO.Directory.CreateDirectory(pathBalance)
        End If
 
        '2. Si le répertoire de la structure n'existe pas on le crée
        If Not System.IO.Directory.Exists(pathBalance & "/" & idStructure) Then
            System.IO.Directory.CreateDirectory(pathBalance & "/" & idStructure)
        End If
 
        '3. Création du fichier 
        If Not System.IO.File.Exists(pathBalance & "/" & idStructure & "/balance.txt") Then
            System.IO.File.Create(pathBalance & "/" & idStructure & "/balance.txt")
        End If
 
        Dim fs As System.IO.StreamWriter
        fs = New System.IO.StreamWriter(pathBalance & "/" & idStructure & "/balance.txt", False)
        fs.Write(Me.txtResultat.Text)
        fs.Close()
        fs.Dispose()
Mais si mon fichier n'existe pas et qu'il est créé alors la ligne :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
fs = New System.IO.StreamWriter(pathBalance & "/" & idStructure & "/balance.txt", False)
plante avec l'erreur : le fichier est utilisé par un autre processus.

Comment savoir libéré le fichier créer?
Ou alors comment détecter la fin de la création du ficher?

Ou tout autre solution qui résoudrait mon problème.

Merci d'avance