Search code examples
c#compact-frameworkwindows-ce

StreamWriter cannot find part of Path


I am using a Falcon X3 mobile computer on vs 2008. I am trying to write a text file to the local directory.

a) Is this possible?

b) It throws an error " could not find a part of the path".

Here is my code:

 var output = new List<string>();

var importDirectory = string.Format(@"C:\Temp");

var timeStamp = DateTime.Now.ToString("dd-MM-yyyy_HH-mm-ss");

var fileName = string.Format("Test_{0}.txt", timeStamp);

var path = string.Format(@"{0}\{1}", importDirectory, fileName);

output.Add("01");

output.Add(path);

 var streamWriter = new StreamWriter(path);

streamWriter.WriteLine(output.ToString());

Please can any one suggest me code or solution?

Thanks.


Solution

  • Windows CE devices don't have a "C:\" directory. The root directory is "\", so your path should be "\Temp". However for best practices I would not get in the habit of storing files in your root directory, instead use Environment.GetFolderPath(...) to get the path of your user's personal folder (My Documents) or the application data folder for you application.