Générer un fichier dans le dossier d'installation

Résolu
hanadakia Messages postés 48 Date d'inscription mercredi 21 mai 2014 Statut Membre Dernière intervention 30 mai 2018 - 14 nov. 2017 à 17:40
Whismeril Messages postés 18398 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 28 mai 2023 - 14 nov. 2017 à 18:15
bonjour,

voici le code que j'utilise pour générer un fichier texte. Je veux que mon fichier se génère dans le dossier d'installation de l'application :

  Dim mydocpath As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
Using sw As New StreamWriter(mydocpath & Convert.ToString("\WriteLines.txt"),True)

sw.WriteLine(installedprinter)
sw.WriteLine(papersize)
sw.WriteLine(papersource)
sw.WriteLine(pageorientation)
sw.WriteLine(margingauche)
sw.WriteLine(margindroit)
sw.WriteLine(marginhaut)
sw.WriteLine(marginbas)
End Using

Merci d'avance

2 réponses

Whismeril Messages postés 18398 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 28 mai 2023 623
14 nov. 2017 à 17:46
Regarde Application.StartUpPath
0
hanadakia Messages postés 48 Date d'inscription mercredi 21 mai 2014 Statut Membre Dernière intervention 30 mai 2018
14 nov. 2017 à 17:57
Merci ça marche bien
0
Whismeril Messages postés 18398 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 28 mai 2023 623
14 nov. 2017 à 18:05
De rien,

C’est plus simple d’utliser la classe File pour écrire un fichier texte, qu’un streamwirter.
0
Whismeril Messages postés 18398 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 28 mai 2023 623
14 nov. 2017 à 18:11
Dim lignes() As String = { installedprinter, papersize, papersource, pageorientation, margingauche, margindroit, marginhaut, marginbas }
File.WriteAllLines(Application.StartupPath & "\monfichier.txt", lignes)
0
Whismeril Messages postés 18398 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 28 mai 2023 623
Modifié le 14 nov. 2017 à 18:15
Cependant, on dirait que tu veux enregistrer les paramètres de l'imprimante, pour j'imagine les recharger par la suite.
Il s'agit donc d'une configuration de ton application.

Je te conseille donc d'utiliser le fichier de config de VB.Net, c'est fait exprès pour.
https://msdn.microsoft.com/fr-fr/library/a65txexh.aspx
0