zoukankan      html  css  js  c++  java
  • window store app 附件读取

      1   public static async Task<bool> DisplayApplicationPicker(string folderName, string fileName)
      2         {
      3             // Path to the file in the app package to launch  
      4            
      5 
      6             MessageDialog message = null;
      7             StorageFolder storageFolder = null;
      8             StorageFile GetStorageFile = null;
      9 
     10             IReadOnlyList<StorageFolder> storageFolders;
     11 
     12             bool isExist = false;
     13             try
     14             {
     15 
     16                 try
     17                 {
     18 
     19                     //在指定的应用程序文件夹下查找指定的文件
     20                     storageFolder = ApplicationData.Current.LocalFolder;
     21                     storageFolders = await storageFolder.GetFoldersAsync();
     22                     isExist = storageFolders.Any(folder => folder.Name == folderName);
     23                     if (isExist)
     24                     {
     25                         storageFolder = await ApplicationData.Current.LocalFolder.GetFolderAsync(folderName);
     26 
     27                     }
     28                     else
     29                     {
     30                         storageFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(folderName);
     31                     }
     32 
     33                 }
     34                 catch (System.IO.FileNotFoundException ex)
     35                 {
     36                     message = new MessageDialog(ex.Message);
     37                     message.ShowAsync();
     38                 }
     39                 //判断是否有该文件
     40                 try
     41                 {
     42                     //在指定的应用程序文件夹下查找指定的文件
     43                     if (isExist)
     44                     {
     45                         IReadOnlyList<StorageFile> files = await storageFolder.GetFilesAsync();
     46                         bool isExistfile = files.Any(file => file.Name == fileName);
     47                         if (!isExistfile)
     48                         {
     49                             message = new MessageDialog("Didn't find the specified file");
     50                             message.ShowAsync();
     51                             //todo: Written to the file Method
     52                         }
     53                         else
     54                         {
     55                             GetStorageFile = await storageFolder.GetFileAsync(fileName);
     56                         }
     57 
     58 
     59                     }
     60 
     61                 }
     62                 catch (System.IO.FileNotFoundException ex)
     63                 {
     64                     message = new MessageDialog(ex.Message);
     65                     message.ShowAsync();
     66                 }
     67 
     68 
     69                 if (GetStorageFile != null)
     70                 {
     71                     // Set the option to show the picker  
     72                     var options = new Windows.System.LauncherOptions();
     73                     options.DisplayApplicationPicker = true;
     74 
     75                     // Launch the retrieved file  
     76                     bool success = await Windows.System.Launcher.LaunchFileAsync(GetStorageFile, options);
     77 
     78                     if (success)
     79                     {
     80                         // File launched 
     81                         return true;
     82 
     83                     }
     84                     else
     85                     {
     86                         // File launch failed  
     87                         message = new MessageDialog("Please choose other open way");
     88                         message.ShowAsync();
     89                         return false;
     90 
     91                     }
     92                 }
     93                 else
     94                 {
     95                     message = new MessageDialog( "Didn't find the specified file");
     96                     message.ShowAsync();
     97                     return false;
     98                 }
     99                 
    100 
    101             }
    102             catch (Exception ex)
    103             {
    104                 message = new MessageDialog(ex.Message);
    105                 message.ShowAsync();
    106                 return false;
    107             }
    108 
    109         }
  • 相关阅读:
    memmove 的实现
    [转]SGI STL 红黑树(Red-Black Tree)源代码分析
    [转]让我看了很有感触
    [转]C++ list 类学习笔记
    [转]码农自白:这样成为谷歌工程师
    [转]Traits 编程技法+模板偏特化+template参数推导+内嵌型别编程技巧
    泛型指针,原生指针和智能指针
    [转]C++基本功和 Design Pattern系列 ctor & dtor
    python+opencv滤波操作
    python+opencv阈值
  • 原文地址:https://www.cnblogs.com/Mengyl/p/3741488.html
Copyright © 2011-2022 走看看