• Windows Phone 有关独立存储(一)


    private const string foldername = "temp1";
    private const string filename = foldername + "/address.txt";
    private const string settingname = "sname"; 

    1.创建文件夹

    private void button1_Click(object sender, RoutedEventArgs e) 
    { 
         using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication()) 
         { 
              file.CreateDirectory(foldername); 
          } 
    } 

    2.检查文件夹是否存在

    private void button2_Click(object sender, RoutedEventArgs e) 
    { 
         using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication()) 
         { 
              if (file.DirectoryExists(foldername)) 
              { 
                   MessageBox.Show("已存在"); 
              } 
               else
              { 
                   MessageBox.Show("不存在"); 
               } 
          } 
    } 

    3.删除目录

     private void button3_Click(object sender, RoutedEventArgs e) 
    { 
        using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication()) 
        { 
            file.DeleteDirectory(foldername); 
        } 
    } 

    4.创建文件

    private void button4_Click(object sender, RoutedEventArgs e) 
    { 
        using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication()) 
        { 
             IsolatedStorageFileStream stream = file.CreateFile(filename); 
             stream.Close(); 
         } 
    } 

    5.检查文件是否存在

    private void button5_Click(object sender, RoutedEventArgs e) 
    { 
         using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication()) 
         { 
              if (file.FileExists(filename)) 
              { 
                  MessageBox.Show("已存在" + filename); 
              } 
              else
              { 
                  MessageBox.Show("不存在"); 
              } 
         } 
    } 

    6.删除文件

    private void button6_Click(object sender, RoutedEventArgs e) 
    { 
        using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication()) 
        { 
            file.DeleteFile(filename); 
        } 
    } 

    7.向文件中增加内容

    private void button7_Click(object sender, RoutedEventArgs e) 
    { 
         using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication()) 
         { 
              using (IsolatedStorageFileStream stream = file.OpenFile(filename, FileMode.OpenOrCreate, FileAccess.ReadWrite)) 
              { 
                  StreamWriter writer = new StreamWriter(stream); 
                  writer.WriteLine(textBox1.Text); 
                  writer.Close(); 
                  textBox1.Text = ""; 
              }         
         } 
    } 

    8.读取文件内容

    private void button8_Click(object sender, RoutedEventArgs e) 
    { 
         using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication()) 
         { 
             using (IsolatedStorageFileStream stream = file.OpenFile(filename, FileMode.OpenOrCreate, FileAccess.ReadWrite)) 
             { 
                 using (StreamReader  reader=new StreamReader (stream)) 
                 { 
                     textBox1.Text = reader.ReadToEnd(); 
                  } 
              } 
      
         } 
    } 

    9、程序配置信息保存

    private void button9_Click(object sender, RoutedEventArgs e) 
    { 
        IsolatedStorageSettings.ApplicationSettings[settingname] = textBox2.Text; 
        IsolatedStorageSettings.ApplicationSettings.Save(); 
        textBox2.Text = ""; 
    } 

    10.程序配置信息读取

    private void button10_Click(object sender, RoutedEventArgs e) 
    { 
        if (IsolatedStorageSettings.ApplicationSettings.Contains(settingname)) 
        { 
            textBox2.Text = IsolatedStorageSettings.ApplicationSettings[settingname].ToString(); 
        } 
    } 
  • 相关阅读:
    使用PHP绘制统计图
    微信公众平台商户模块
    jQuery Mobile入门教程
    2013中国微信公众平台用户研究报告
    WordPress的SEO技术
    微信公众平台消息接口星标功能
    微信5.0打飞机怎么取得高分?
    微信公众平台的服务号和订阅号
    微信公众平台开发(58)自定义菜单
    微信公众平台开发(57)Emoji表情符号
  • 原文地址:https://www.cnblogs.com/lihaibo-Leao/p/3141631.html
Copyright © 2020-2023  润新知