Bonjour à tous,

j'ai mon appli sur un windows mobile 5.

Je souhaiterais simplement créer un fichier dans le répertoire \My Documents mais il me marque IOException.

Voici le code

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
private void Write2File(string msg, string filePath)
        {
            try
            {
                if (!File.Exists(filePath))
                {
                    File.Create(filePath);
                }
                System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Append);
                System.IO.StreamWriter sw = new System.IO.StreamWriter(fs);
                sw.WriteLine(msg);
                sw.Flush();
                sw.Close();
                fs.Close();
            }
            catch (IOException ioe)
            {
                Write2File(ioe.StackTrace, "\\My Documents\\PDA_LOG.log");
            }
 
        }
L'exception est catchée au niveau du File.Create(filepath);

Et voici l'exception pas très explicite je dois le reconnaitre

at System.IO.__Error.WinIOError(Int32 errorCode, String str)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
at System.IO.File.Create(String path, Int32 bufferSize)
at System.IO.File.Create(String path)
at NIS_2008_Sync_Data.SyncNisData.Write2File(String msg, String filePath)
at NIS_2008_Sync_Data.SyncNisData.dropTables()
at NIS_2008_Sync_Data.SyncNisData.getNisData()
at NIS_2008_Sync_Data.SyncDataForm.buttonImport_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.ButtonBase.WnProc(WM wm, Int32 wParam, Int32 lParam)
at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
at Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain)
at System.Windows.Forms.Application.Run(Form fm)
at NIS_2008_Sync_Data.LaunchSyncDataForm.Main()

at System.IO.__Error.WinIOError(Int32 errorCode, String str)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
at System.IO.File.Create(String path, Int32 bufferSize)
at System.IO.File.Create(String path)
at NIS_2008_Sync_Data.SyncNisData.Write2File(String msg, String filePath)
at NIS_2008_Sync_Data.SyncNisData.getNisData()
at NIS_2008_Sync_Data.SyncDataForm.buttonImport_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.ButtonBase.WnProc(WM wm, Int32 wParam, Int32 lParam)
at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
at Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain)
at System.Windows.Forms.Application.Run(Form fm)
at NIS_2008_Sync_Data.LaunchSyncDataForm.Main()

at System.IO.__Error.WinIOError(Int32 errorCode, String str)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
at System.IO.File.Create(String path, Int32 bufferSize)
at System.IO.File.Create(String path)
at NIS_2008_Sync_Data.SyncNisData.Write2File(String msg, String filePath)
at NIS_2008_Sync_Data.SyncNisData.getNisData()
at NIS_2008_Sync_Data.SyncDataForm.buttonImport_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.ButtonBase.WnProc(WM wm, Int32 wParam, Int32 lParam)
at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
at Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain)
at System.Windows.Forms.Application.Run(Form fm)
at NIS_2008_Sync_Data.LaunchSyncDataForm.Main()
Je suppose que c'est un problème de droits.

Comment puis-je résoudre ce problème??

D'avance merci pour vos réponses.