IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

System.IO.FileNotFoundException: Impossible de trouver le fichier


Sujet :

C#

  1. #1
    Membre régulier
    Homme Profil pro
    Technicien réseau
    Inscrit en
    Janvier 2010
    Messages
    119
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations professionnelles :
    Activité : Technicien réseau
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Janvier 2010
    Messages : 119
    Points : 77
    Points
    77
    Par défaut System.IO.FileNotFoundException: Impossible de trouver le fichier
    Bonjour,

    je développe en ce moment une application C# avec une bdd MYSQL. Je génère des messages erreurs dans un fichier erreur.txt et en local tout fonctionne correctement.

    Depuis le déploiement sur un serveur distant, le fichier d'erreur est impossible à trouver lorsqu'un utilisateur installe l'application.

    J'ai l'impression que le fichier erreur.txt n'est pas intègre aux fichiers d'installation. Lorsque je copie le fichier dans le répertoire spécifié dans le message d'erreur ci-dessous, tout fonctionne. Mais je souhaiterais que cela se fasse automatiquement à l'installation.

    Vous trouvez ci-dessous le message d'erreur généré.

    Consultez la fin de ce message pour plus de détails sur l'appel du débogage
    juste-à-temps (JIT) à la place de cette boîte de dialogue.

    ************** Texte de l'exception **************
    System.IO.FileNotFoundException: Impossible de trouver le fichier 'C:\Users\degio1er\AppData\Local\Apps\2.0\ZV0X8DHR.7TL\BP0331BP.66X\impo..tion_0000000000000000_0000.0000_169d9c37252e2b0f\erreur.txt'.
    Nom de fichier*: 'C:\Users\degio1er\AppData\Local\Apps\2.0\ZV0X8DHR.7TL\BP0331BP.66X\impo..tion_0000000000000000_0000.0000_169d9c37252e2b0f\erreur.txt'
    à System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
    à System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
    à System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
    à System.IO.FileStream..ctor(String path, FileMode mode)
    à IMPORTATION.Control_Fichier_CONFRERE.FormControl_Fichier_Load(Object sender, EventArgs e)
    à System.Windows.Forms.Form.OnLoad(EventArgs e)
    à System.Windows.Forms.Form.OnCreateControl()
    à System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
    à System.Windows.Forms.Control.CreateControl()
    à System.Windows.Forms.Control.WmShowWindow(Message& m)
    à System.Windows.Forms.Control.WndProc(Message& m)
    à System.Windows.Forms.ScrollableControl.WndProc(Message& m)
    à System.Windows.Forms.ContainerControl.WndProc(Message& m)
    à System.Windows.Forms.Form.WmShowWindow(Message& m)
    à System.Windows.Forms.Form.WndProc(Message& m)
    à System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    à System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    à System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


    ************** Assemblys chargés **************
    mscorlib
    Version de l'assembly*: 4.0.0.0
    Version Win32*: 4.0.30319.34011 built by: FX45W81RTMGDR
    CodeBase*: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
    ----------------------------------------
    IMPORTATION
    Version de l'assembly*: 1.0.0.0
    Version Win32*: 1.0.0.0
    CodeBase*: file:///C:/Users/degio1er/AppData/Local/Apps/2.0/ZV0X8DHR.7TL/BP0331BP.66X/impo..tion_0000000000000000_0000.0000_169d9c37252e2b0f/IMPORTATION.exe
    ----------------------------------------
    System.Windows.Forms
    Version de l'assembly*: 4.0.0.0
    Version Win32*: 4.0.30319.33440 built by: FX45W81RTMREL
    CodeBase*: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
    ----------------------------------------
    System.Drawing
    Version de l'assembly*: 4.0.0.0
    Version Win32*: 4.0.30319.33440 built by: FX45W81RTMREL
    CodeBase*: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
    ----------------------------------------
    System
    Version de l'assembly*: 4.0.0.0
    Version Win32*: 4.0.30319.34003 built by: FX45W81RTMGDR
    CodeBase*: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
    ----------------------------------------
    System.Configuration
    Version de l'assembly*: 4.0.0.0
    Version Win32*: 4.0.30319.33440 built by: FX45W81RTMREL
    CodeBase*: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
    ----------------------------------------
    System.Xml
    Version de l'assembly*: 4.0.0.0
    Version Win32*: 4.0.30319.33440 built by: FX45W81RTMREL
    CodeBase*: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
    ----------------------------------------
    System.Data
    Version de l'assembly*: 4.0.0.0
    Version Win32*: 4.0.30319.33440 built by: FX45W81RTMREL
    CodeBase*: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.Data/v4.0_4.0.0.0__b77a5c561934e089/System.Data.dll
    ----------------------------------------
    System.Core
    Version de l'assembly*: 4.0.0.0
    Version Win32*: 4.0.30319.33440 built by: FX45W81RTMREL
    CodeBase*: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
    ----------------------------------------
    System.Transactions
    Version de l'assembly*: 4.0.0.0
    Version Win32*: 4.0.30319.33440 built by: FX45W81RTMREL
    CodeBase*: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.Transactions/v4.0_4.0.0.0__b77a5c561934e089/System.Transactions.dll
    ----------------------------------------
    System.EnterpriseServices
    Version de l'assembly*: 4.0.0.0
    Version Win32*: 4.0.30319.33440 built by: FX45W81RTMREL
    CodeBase*: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.EnterpriseServices/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll
    ----------------------------------------
    mscorlib.resources
    Version de l'assembly*: 4.0.0.0
    Version Win32*: 4.0.30319.33440 built by: FX45W81RTMREL
    CodeBase*: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/mscorlib.resources/v4.0_4.0.0.0_fr_b77a5c561934e089/mscorlib.resources.dll
    ----------------------------------------
    System.Windows.Forms.resources
    Version de l'assembly*: 4.0.0.0
    Version Win32*: 4.0.30319.33440 built by: FX45W81RTMREL
    CodeBase*: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms.resources/v4.0_4.0.0.0_fr_b77a5c561934e089/System.Windows.Forms.resources.dll
    ----------------------------------------

    ************** Débogage JIT **************
    Pour activer le débogage juste-à-temps (JIT), le fichier de configuration pour cette
    application ou cet ordinateur (machine.config) doit avoir la valeur
    jitDebugging définie dans la section system.windows.forms.
    L'application doit également être compilée avec le débogage
    activé.

    Par exemple*:

    <configuration>
    <system.windows.forms jitDebugging="true" />
    </configuration>

    Lorsque le débogage juste-à-temps est activé, les exceptions non gérées
    seront envoyées au débogueur JIT inscrit sur l'ordinateur
    plutôt que d'être gérées par cette boîte de dialogue.



  2. #2
    Membre confirmé
    Avatar de nouanda
    Homme Profil pro
    Hobbyist
    Inscrit en
    Mai 2002
    Messages
    246
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Australie

    Informations professionnelles :
    Activité : Hobbyist

    Informations forums :
    Inscription : Mai 2002
    Messages : 246
    Points : 627
    Points
    627
    Par défaut
    Est-il possible que le chemin soit codé en dur, et que donc forcément, un autre utilisateur avec un autre chemin pour le dossier AppData ne le verra pas?

    Sinon, tu peux ajouter le fichier dans ta solution sous VS, et choisir l'option qui va bien (cf screenshot), soit vérifier son existence au lancement de l'application, et le créer si il n'existe pas.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    if (!File.Exists("tonfichier"))
                {
                    File.Create("tonfichier").Close();
                }
    Nom : copier.JPG
Affichages : 2096
Taille : 23,0 Ko
    " Entre le Savoir et le Pouvoir, il y a le Vouloir "

    Desole pour les accents, je suis en QWERTY...

  3. #3
    Membre régulier
    Homme Profil pro
    Technicien réseau
    Inscrit en
    Janvier 2010
    Messages
    119
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations professionnelles :
    Activité : Technicien réseau
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Janvier 2010
    Messages : 119
    Points : 77
    Points
    77
    Par défaut
    Bonjour nouanda,

    Merci pour ta réponse.

    J'ai fait la mise à jour au niveau de la proprieté du fichier comme tu peux le voir dans la capture ecran ci-dessous.

    Nom : Capture.JPG
Affichages : 2101
Taille : 29,8 Ko

    Dans mon programme je charge le fichier.txt, le renomme à la date du jour et je l'ouvre automatiquement à la fin du traitement .

    L'erreur ci-dessous apparaît lorsque j'essaie d'ouvrir le fichier. En fait le fichier renommé est introuvable.

    Consultez la fin de ce message pour plus de détails sur l'appel du débogage
    juste-à-temps (JIT) à la place de cette boîte de dialogue.

    ************** Texte de l'exception **************
    System.IO.DirectoryNotFoundException: Impossible de trouver une partie du chemin d'accès 'C:\Users\degio1er\AppData\Local\Apps\2.0\ZV0X8DHR.7TL\BP0331BP.66X\impo..tion_0000000000000000_0000.0000_179bbbae20b69d4f\fichiers_generer\VIREMENT TEST 09032017.txt'.
    à System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
    à System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
    à System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
    à System.IO.FileStream..ctor(String path, FileMode mode)
    à IMPORTATION.FormBIAO.button1BIAO_Click(Object sender, EventArgs e)
    à System.Windows.Forms.Control.OnClick(EventArgs e)
    à System.Windows.Forms.Button.OnClick(EventArgs e)
    à System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
    à System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
    à System.Windows.Forms.Control.WndProc(Message& m)
    à System.Windows.Forms.ButtonBase.WndProc(Message& m)
    à System.Windows.Forms.Button.WndProc(Message& m)
    à System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    à System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    à System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


    ************** Assemblys chargés **************
    mscorlib
    Version de l'assembly*: 4.0.0.0
    Version Win32*: 4.0.30319.34011 built by: FX45W81RTMGDR
    CodeBase*: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
    ----------------------------------------
    IMPORTATION
    Version de l'assembly*: 1.0.0.0
    Version Win32*: 1.0.0.0
    CodeBase*: file:///C:/Users/degio1er/AppData/Local/Apps/2.0/ZV0X8DHR.7TL/BP0331BP.66X/impo..tion_0000000000000000_0000.0000_179bbbae20b69d4f/IMPORTATION.exe
    ----------------------------------------
    System.Windows.Forms
    Version de l'assembly*: 4.0.0.0
    Version Win32*: 4.0.30319.33440 built by: FX45W81RTMREL
    CodeBase*: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
    ----------------------------------------
    System.Drawing
    Version de l'assembly*: 4.0.0.0
    Version Win32*: 4.0.30319.33440 built by: FX45W81RTMREL
    CodeBase*: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
    ----------------------------------------
    System
    Version de l'assembly*: 4.0.0.0
    Version Win32*: 4.0.30319.34003 built by: FX45W81RTMGDR
    CodeBase*: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
    ----------------------------------------
    System.Configuration
    Version de l'assembly*: 4.0.0.0
    Version Win32*: 4.0.30319.33440 built by: FX45W81RTMREL
    CodeBase*: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
    ----------------------------------------
    System.Xml
    Version de l'assembly*: 4.0.0.0
    Version Win32*: 4.0.30319.33440 built by: FX45W81RTMREL
    CodeBase*: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
    ----------------------------------------
    System.Windows.Forms.resources
    Version de l'assembly*: 4.0.0.0
    Version Win32*: 4.0.30319.33440 built by: FX45W81RTMREL
    CodeBase*: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms.resources/v4.0_4.0.0.0_fr_b77a5c561934e089/System.Windows.Forms.resources.dll
    ----------------------------------------
    System.Data
    Version de l'assembly*: 4.0.0.0
    Version Win32*: 4.0.30319.33440 built by: FX45W81RTMREL
    CodeBase*: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.Data/v4.0_4.0.0.0__b77a5c561934e089/System.Data.dll
    ----------------------------------------
    System.Core
    Version de l'assembly*: 4.0.0.0
    Version Win32*: 4.0.30319.33440 built by: FX45W81RTMREL
    CodeBase*: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
    ----------------------------------------
    System.Numerics
    Version de l'assembly*: 4.0.0.0
    Version Win32*: 4.0.30319.33440 built by: FX45W81RTMREL
    CodeBase*: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Numerics/v4.0_4.0.0.0__b77a5c561934e089/System.Numerics.dll
    ----------------------------------------
    mscorlib.resources
    Version de l'assembly*: 4.0.0.0
    Version Win32*: 4.0.30319.33440 built by: FX45W81RTMREL
    CodeBase*: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/mscorlib.resources/v4.0_4.0.0.0_fr_b77a5c561934e089/mscorlib.resources.dll
    ----------------------------------------

    ************** Débogage JIT **************
    Pour activer le débogage juste-à-temps (JIT), le fichier de configuration pour cette
    application ou cet ordinateur (machine.config) doit avoir la valeur
    jitDebugging définie dans la section system.windows.forms.
    L'application doit également être compilée avec le débogage
    activé.

    Par exemple*:

    <configuration>
    <system.windows.forms jitDebugging="true" />
    </configuration>

    Lorsque le débogage juste-à-temps est activé, les exceptions non gérées
    seront envoyées au débogueur JIT inscrit sur l'ordinateur
    plutôt que d'être gérées par cette boîte de dialogue.


  4. #4
    Membre régulier
    Homme Profil pro
    Technicien réseau
    Inscrit en
    Janvier 2010
    Messages
    119
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations professionnelles :
    Activité : Technicien réseau
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Janvier 2010
    Messages : 119
    Points : 77
    Points
    77
    Par défaut
    Le script

    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
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
     
     //On recupere la date du jour afin de renommer le fichier du jour
                     DateTime datej = DateTime.Today;
                     string date2 = Convert.ToString(datej).Replace("/", "");
                     string datejour = date2.Substring(0, 8);
                     string nomclient = TXTNOMDONNEUR.Text.Trim();
                     string fichier = "VIREMENT " + nomclient + " " + datejour + ".txt";
     
                     TXTNOMDONNEUR.Text = "";
     
                    using (FileStream fstream = new FileStream(Application.StartupPath + "\\fichier.txt", FileMode.OpenOrCreate))
                    {
                        // On renomme le fichhier a la date du jour
                        using (FileStream fstreamNew = new FileStream(Application.StartupPath + "\\fichiers_generer" + "\\" + fichier + " ", FileMode.Create))
                        {
                            fstream.CopyTo(fstreamNew);
                        }
                    }
     
                    //**********************************************************************************************************************
                    // On ouvre le fichier generer automatiquement.
                     try
                     {
                         if (!File.Exists(Application.StartupPath + "\\fichier.txt"))
                         {
                             File.Create(Application.StartupPath + "\\fichier.txt").Close();
                         }
                         Process proc = new Process();
                         proc.StartInfo = new ProcessStartInfo(Application.StartupPath + "\\fichiers_generer" + "\\" + fichier);
                         proc.Start();
                     }
                     catch (Win32Exception ex)
                     {
                         MessageBox.Show(ex.Message);
                     }

  5. #5
    Membre confirmé
    Avatar de nouanda
    Homme Profil pro
    Hobbyist
    Inscrit en
    Mai 2002
    Messages
    246
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Australie

    Informations professionnelles :
    Activité : Hobbyist

    Informations forums :
    Inscription : Mai 2002
    Messages : 246
    Points : 627
    Points
    627
    Par défaut
    Une question : le fichier "fichier.txt", il est vide, ou pré-rempli?

    Si il est vide, pas besoin de le copier dans un nouveau

    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
                string date = String.Format("{0:ddMMyyyy}", DateTime.Now);
                string nomclient = TXTNOMDONNEUR.Text.Trim();
                string newfile = Application.StartupPath + "\\VIREMENT " + nomclient + " " + date + ".txt";
                try
                {
                    //on crée le fichier newfile si il n'existe pas
                    if (!File.Exists(newfile))
                    {
                        File.Create(newfile).Close();
                    }
                    //on ouvre le notepad
                    Process.Start(newfile);
                }
                catch(Exception ex) // à toi de gérer les exceptions
                {
                    // todo
                }
    " Entre le Savoir et le Pouvoir, il y a le Vouloir "

    Desole pour les accents, je suis en QWERTY...

  6. #6
    Membre régulier
    Homme Profil pro
    Technicien réseau
    Inscrit en
    Janvier 2010
    Messages
    119
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations professionnelles :
    Activité : Technicien réseau
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Janvier 2010
    Messages : 119
    Points : 77
    Points
    77
    Par défaut
    Le fichier.txt est celui que je rempli au départ et que je renomme ensuite avec la date du jour. C'est la raison d’être du code ci-dessous :

    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
     
     
     //On récupéré la date du jour afin de renommer le fichier du jour
                     DateTime datej = DateTime.Today;
                     string date2 = Convert.ToString(datej).Replace("/", "");
                     string datejour = date2.Substring(0, 8);
                     string nomclient = TXTNOMDONNEURBIAO.Text.Trim();
                     string fichier = "VIREMENT " + nomclient + " " + datejour + ".txt";
     
                     TXTNOMDONNEURBIAO.Text = "";
     
                    using (FileStream fstream = new FileStream(Application.StartupPath + "\\fichier.txt", FileMode.OpenOrCreate))
                    {
                        // On renomme le fichier a la date du jour et le copie dans le repertoire fichiers_generer
                        using (FileStream fstreamNew = new FileStream(Application.StartupPath + "\\fichiers_generer" + "\\" + fichier + " ", FileMode.Create))
                        {
                            fstream.CopyTo(fstreamNew);
                        }
                    }

  7. #7
    Membre régulier
    Homme Profil pro
    Technicien réseau
    Inscrit en
    Janvier 2010
    Messages
    119
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations professionnelles :
    Activité : Technicien réseau
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Janvier 2010
    Messages : 119
    Points : 77
    Points
    77
    Par défaut
    Problème résolu. Merci à tous

    Je fixe le fichier au départ
    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
     
    // On fixe le fichier de transaction. 
     string chaine = (Application.StartupPath + "\\fichier.txt");
     
    try
                {
                    //on crée le fichier newfile si il n'existe pas
                    if (!File.Exists(chaine))
                    {
                        File.Create(chaine).Close();
                    }
     
                }
                catch (Exception ex) // à toi de gérer les exceptions
                {
                    // todo
                }
    Le code de fin

    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
    26
    27
    28
    29
    30
     
     //On récupère la date du jour afin de renommer le fichier du jour
                     DateTime datej = DateTime.Today;
                     string date2 = Convert.ToString(datej).Replace("/", "");
                     string datejour = date2.Substring(0, 8);
                     string nomclient = TXTNOMDONNEUR.Text.Trim();
                     string fichier = "VIREMENT " + nomclient + " " + datejour + ".txt";
     
     
                    using (FileStream fstream = new FileStream(Application.StartupPath + "\\fichier.txt", FileMode.OpenOrCreate))
                    {
                        // On renomme le fichhier a la date du jour
                        using (FileStream fstreamNew = new FileStream(Application.StartupPath + "\\" + fichier + " ", FileMode.Create))
                        {
                            fstream.CopyTo(fstreamNew);
                        }
                    }
     
                    //**********************************************************************************************************************
                    // On ouvre le fichier generé automatiquement.
                     try
                     {                     
                         Process proc = new Process();
                         proc.StartInfo = new ProcessStartInfo(Application.StartupPath + "\\" + fichier);
                         proc.Start();
                     }
                     catch (Win32Exception ex)
                     {
                         MessageBox.Show(ex.Message);
                     }

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. impossible de trouver le fichier systeme.pas
    Par pat34 dans le forum Langage
    Réponses: 8
    Dernier message: 08/02/2013, 16h57
  2. [load] Impossible de trouver le fichier à charger
    Par Userbn dans le forum MATLAB
    Réponses: 2
    Dernier message: 05/06/2008, 10h38
  3. Réponses: 1
    Dernier message: 14/02/2007, 15h05
  4. Réponses: 30
    Dernier message: 02/11/2006, 09h53
  5. [Erreur]impossible de trouver le fichier de config du moteur
    Par julietteste dans le forum Bases de données
    Réponses: 5
    Dernier message: 10/05/2005, 18h34

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo