Dim FileString As String = String.Empty Dim FichierIni As String = My.Application.Info.DirectoryPath & My.Resources.Repart 'c'est cette ligne qui bloque Dim fr As StreamReader = New System.IO.StreamReader(FichierIni, System.Text.Encoding.Default, True) Try Do FileString = fr.ReadLine If Not FileString = "" Then ..................
D'autre part, je ne peux pas savoir d'avance le chemin où seront rangés les fichiers de l'utilisateur.
My.Application.Info.DirectoryPath
Dim ligne As String Dim p1 As New System.IO.StreamReader(CStr(My.Application.Info.DirectoryPath & "\nomFichier.txt")) While p1.Peek() >= 0 ' lecture ligne = p1.ReadLine() End While p1.Close()
MainNotifyIcon.Icon = My.Resources.Courbe
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPrivate Function LireFichierTexteIncorpore(ByVal FichierIncorpore As String) As String() 'NE PAS OUBLIER D'INCORPORER LE FICHIER AU PROJET 'POUR CELA SELECTIONNER LE FICHIER DANS L'EXPLORATEUR DE SOLUTION PUIS PROPRIETE/ACTION DE GENERATION = RESSOURCE INCORPOREE Dim fluxEntree As System.IO.Stream = _ Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream(My.Application.Info.AssemblyName & "." & FichierIncorpore) Dim fluxLecture As New System.IO.StreamReader(fluxEntree, System.Text.Encoding.Default) Dim lignesTexte As String() = Nothing Dim index As Integer = 0 Do If fluxLecture.EndOfStream = True Then Exit Do Else Dim chaine As String = fluxLecture.ReadLine Array.Resize(lignesTexte, index + 1) lignesTexte(index) = chaine index += 1 End If Loop Return lignesTexte End Function
c'est lire un fichier texte placé en Ressource sans que ce fichier ne soit copié et n'apparaisse sur le disque
Dim FichierIni As String = My.Resources.Repart Dim fr = New System.IO.StreamReader(FichierIni, System.Text.Encoding.Default, True)
dim chaine as string = My.Resources.Repart
Option Explicit On Public Class Form1 ' déclarer 3 objets sur form1 ' TextBox1 + propriété Multiline = True ' Listbox1 ' Button1 Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim f As String = My.Application.Info.DirectoryPath & "\Repart.txt" ' depuis ressource, copie fichier sur disque System.IO.File.WriteAllText(f, My.Resources.Repart) ' Lit le fichier sur disque et le met en double dans textbox1 et listbox1 TextBox1.Text = "" ListBox1.Items.Clear() Dim a As String Dim p As New System.IO.StreamReader(CStr(f)) While p.Peek() >= 0 ' lecture a = p.ReadLine() If a <> "" Then TextBox1.Text = TextBox1.Text & a & vbCrLf ListBox1.Items.Add(a) End If End While p.Close() Kill(f) End Sub End Class
While p.Peek() >= 0 ...... End While 'd'une part et Do .......... Loop while a Is Not Nothing 'd'autre part ? Merci.
My.Settings.MaVariable = "Toto" My.Settings.Save Dim Toto As String = My.Settings.MaVariable