title: c# cannot write file in specific computer (Solved but don't know reason)
body: <p>I have three computers for testing.</p>
  
  <p>When I write files by my program in XP(PC, and it's my platform of developing) and Win7(PC), both are work.</p>
  
  <p>But in one win7 computer(laptop), it cannot write and no exception come out.</p>
  
  <p>Since Win 7(PC) can run my program perfectly, I think it's not the problem of win 7.</p>
  
  <p>I find that when I use my c# program, it can read but cannot write file.</p>
  
  <p>I try to set the path to c:/Users/Local/AppData and still doesn't work...</p>
  
  <p>The permission to read and write can be accessed, and I can write file manually so maybe it's not because of memory leaking. </p>
  
  <p>And I have tried to open my program in administrator mode.</p>
  
  <p>I don't know any other reason why my program cannot write file in that computer.</p>
  
  <p>I also tried to create directory as:</p>
  
  <pre><code>string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  if (!Directory.Exists(Path.Combine(appDataPath, "test")))
  {
     try
     {
         Directory.CreateDirectory(Path.Combine(appDataPath, "test"));
     }
     catch (Exception ex)
     {
        MessageBox.Show("" + ex.ToString());
     }
  }
  </code></pre>
  
  <p>The code can work in PC(XP and Win7), but still doesn't work in laptop(Win7)...</p>
  
  <p>I also use <code>MessgeBox.Show</code> below the <code>CreateDirectory</code> method, and it can pop out the test message!( that is, the code of <code>CreateDirectory</code> is ran but when I look the parent directory, there isn't exist directory I want to create......( but in PC, the directory is created), I have seen someone have same problem, but the solution doesn't help me......</p>
  
  <p>The code of writing file is:</p>
  
  <pre><code>try
  {
       StreamWriter file = new StreamWriter(System.IO.Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + "\\logfile.txt");
       file.Write("test");
       file.Close();
  }
  catch (Exception ex)
  {
        MessageBox.Show(ex.ToString());
  }
  </code></pre>
  
  <p>Why the strange laptop cannot write files by my program?</p>
  
  <p>Edit:</p>
  
  <p>My program have some operation in the textbox to record data to be saved,</p>
  
  <p>the operation is: When user click at the textbox, the osk.exe( small keyboard) will show up. In my laptop, the osk.exe will show error when I want to run it......</p>
  
  <p>The code to osk.exe is:</p>
  
  <pre><code>System.Diagnostics.Process.Start("" + System.Environment.SystemDirectory + "/osk.exe");
  </code></pre>
  
  <p>While I remove that code, the code to write file simply worked!</p>
  
  <p>Maybe the reason is I check empty textbox first, then user click 'Save' button to write file. Since error occur when the code try to run osk.exe, the textbox may return null or something, then my code of write file won't be operated.</p>