Windows Mobile 6 File IO



 using System;  
 using System.Collections.Generic;  
 using System.IO;  
 using System.Linq;  
 using System.Reflection;  
 public class WindowsMobile6IO  
 {  
   ///  
   /// Get the executing assembly's application path in Windows Mobile 6  
   ///  
   ///  
   internal static string GetApplicationPath()  
   {  
     return Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);  
   }  
   ///  
   /// Get folder path located under your application in Windows Mobile 6  
   /// e.g. If youe application is at "\\Program Files\\TheRock"  
   /// the "Projects" directory under your application can be accessed at "\\Program Files\\TheRock\\Projects"  
   ///  
   internal static string ProjectsFolderPath  
   {  
     get { return Path.Combine(GetApplicationPath(), "Projects"); }  
   }  
   ///  
   /// Create a directory in Windows Mobile 6 application  
   ///  
   internal static void CreateProjectDirectory()  
   {  
     if (!Directory.Exists(ProjectsFolderPath))  
       Directory.CreateDirectory(ProjectsFolderPath);  
   }  
   ///  
   /// Create a new file in Windows Mobile 6 application  
   ///  
   ///  
   internal static string CreateNewFile()  
   {  
     string newFilePath = Path.Combine(ProjectsFolderPath, Guid.NewGuid() + ".xml");  
     using (FileStream fileStream = File.Create(newFilePath))  
     {  
       fileStream.Close();  
     }  
     return newFilePath;  
   }  
   ///  
   /// Get all files under a directory in Windows Mobile 6 application  
   ///  
   ///  
   public static List GetExistingProjects()  
   {  
     return Directory.GetFiles(ProjectsFolderPath).ToList();  
   }  
 /// Write to a file (Windows Mobile 6.0)  
     public static void Write(string filePath, string content)  
     {  
       using (var streamWriter = new StreamWriter(filePath))  
       {  
         streamWriter.Write(content);  
         streamWriter.Close();  
       }  
     }  
 }  

Comments

Popular posts from this blog

WPF How to Dispose ViewModel when the associated UserControl (Not Window) closes?

C# How to unit test Dispatcher

WPF: How to Deep Copy WPF object (e.g. UIElement) ?