Metro style app 文件、文件夹的选择、文件的保存。

简介:

 

 Metro style app 文件、文件夹的选择、文件的保存。

 

1、选择单个文件

public  async void  PickAFile()
{
     FileOpenPicker openPicker = new  FileOpenPicker();
     openPicker.ViewMode = PickerViewMode.Thumbnail;
     openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
     openPicker.FileTypeFilter.Add( ".jpg" );
     openPicker.FileTypeFilter.Add( ".jpeg" );
     openPicker.FileTypeFilter.Add( ".png" );
     StorageFile file = await openPicker.PickSingleFileAsync();
     if  (file != null )
     {
         // Application now has read/write access to the picked file
         msg = "Picked photo: "  + file.Name;
     }
     else
     {
         msg = "Operation cancelled." ;
     }
}

 

 

 

2、选择多个文件

public  async void  PickFiles()
{
     FileOpenPicker openPicker = new  FileOpenPicker();
     openPicker.ViewMode = PickerViewMode.List;
     openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
     openPicker.FileTypeFilter.Add( "*" );
     IReadOnlyList<StorageFile> files = await openPicker.PickMultipleFilesAsync();
     if  (files.Count > 0)
     {
         StringBuilder output = new  StringBuilder( "Picked files:\n" );
         // Application now has read/write access to the picked file(s)
         foreach  (StorageFile file in  files)
         {
             output.Append(file.Name + "\n" );
         }
         msg = output.ToString();
     }
}

 

3、选择文件夹

public  async void  PickFolder()
{
     FolderPicker folderPicker = new  FolderPicker();
     folderPicker.SuggestedStartLocation = PickerLocationId.Desktop;
     folderPicker.FileTypeFilter.Add( ".docx" );
     folderPicker.FileTypeFilter.Add( ".xlsx" );
     folderPicker.FileTypeFilter.Add( ".pptx" );
     folderPicker.FileTypeFilter.Add( ".jpg" );
     folderPicker.FileTypeFilter.Add( ".jpeg" );
     StorageFolder folder = await folderPicker.PickSingleFolderAsync();
     if  (folder != null )
     {
         // Application now has read/write access to all contents in the picked folder (including other sub-folder contents)
         StorageApplicationPermissions.FutureAccessList.AddOrReplace( "PickedFolderToken" , folder);
         msg = "Picked folder: "  + folder.Name;
     }
     else
     {
         msg = "Operation cancelled." ;
     }
 
}

 

 

4、保存文件

public  async void  SaveFile()
{
     FileSavePicker savePicker = new  FileSavePicker();
     savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
     // Dropdown of file types the user can save the file as
     savePicker.FileTypeChoices.Add( "Plain Text" , new  List< string >() { ".txt"  });
     // Default file name if the user does not type one in or select a file to replace
     savePicker.SuggestedFileName = "New Document" ;
     StorageFile file = await savePicker.PickSaveFileAsync();
     if  (file != null )
     {
         // Prevent updates to the remote version of the file until we finish making changes and call CompleteUpdatesAsync.
         CachedFileManager.DeferUpdates(file);
         // write to file
         await FileIO.WriteTextAsync(file, file.Name);
         // Let Windows know that we're finished changing the file so the other app can update the remote version of the file.
         // Completing updates may require Windows to ask for user input.
         FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(file);
         if  (status == FileUpdateStatus.Complete)
         {
             msg = "File "  + file.Name + " was saved." ;
         }
         else
         {
             msg = "File "  + file.Name + " couldn't be saved." ;
         }
     }
}

 

下面是C++版本

1、选择单个文件 

void  BasicHandleCPP::MainPage::PickerAFile_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
     FileOpenPicker^ openPicker = ref  new  FileOpenPicker();
     openPicker->ViewMode = PickerViewMode::Thumbnail;
     openPicker->SuggestedStartLocation = PickerLocationId::PicturesLibrary;
     openPicker->FileTypeFilter->Append( ".jpg" );
     openPicker->FileTypeFilter->Append( ".jpeg" );
     openPicker->FileTypeFilter->Append( ".png" );
 
     create_task(openPicker->PickSingleFileAsync()).then([ this ](StorageFile^ file)
     {
         if  (file)
         {
             Display->Text = "Picked photo: "  + file->Name;
         }
         else
         {
             Display->Text = "Operation cancelled." ;
         }
     });
 
}

 

 

2、选择多个文件

void  BasicHandleCPP::MainPage::PickerFiles_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
     FileOpenPicker^ openPicker = ref  new  FileOpenPicker();
     openPicker->ViewMode = PickerViewMode::List;
     openPicker->SuggestedStartLocation = PickerLocationId::DocumentsLibrary;
     openPicker->FileTypeFilter->Append( "*" );
 
     create_task(openPicker->PickMultipleFilesAsync()).then([ this ](IVectorView<StorageFile^>^ files)
     {
         if  (files->Size > 0)
         {
             String^ output = "Picked files:\n" ;
             std::for_each(begin(files), end(files), [ this , &output](StorageFile ^file)
             {
                 output += file->Name + "\n" ;
             });
             Display->Text = output;
         }
         else
         {
             Display->Text = "Operation cancelled." ;
         }
     });
}

 

 

3、选择文件夹

void  BasicHandleCPP::MainPage::PickerFolder_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
     FolderPicker^ folderPicker = ref  new  FolderPicker();
     folderPicker->SuggestedStartLocation = PickerLocationId::Desktop;
 
     // Users expect to have a filtered view of their folders depending on the scenario.
     // For example, when choosing a documents folder, restrict the filetypes to documents for your application.
     folderPicker->FileTypeFilter->Append( ".docx" );
     folderPicker->FileTypeFilter->Append( ".xlsx" );
     folderPicker->FileTypeFilter->Append( ".pptx" );
 
     create_task(folderPicker->PickSingleFolderAsync()).then([ this ](StorageFolder^ folder)
     {
         if  (folder)
         {
             Display->Text = "Picked folder: "  + folder->Name;
         }
         else
         {
             Display->Text = "Operation cancelled." ;
         }
     });
}

 

4、保存文件

void  BasicHandleCPP::MainPage::SaveFile_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
     FileSavePicker^ savePicker = ref  new  FileSavePicker();
     savePicker->SuggestedStartLocation = PickerLocationId::DocumentsLibrary;
 
     auto plainTextExtensions = ref  new  Platform::Collections::Vector<String^>();
     plainTextExtensions->Append( ".txt" );
     savePicker->FileTypeChoices->Insert( "Plain Text" , plainTextExtensions);
     savePicker->SuggestedFileName = "New Document" ;
 
     create_task(savePicker->PickSaveFileAsync()).then([ this ](StorageFile^ file)
     {
         if  (file != nullptr)
         {
 
             // Prevent updates to the remote version of the file until we finish making changes and call CompleteUpdatesAsync.
             CachedFileManager::DeferUpdates(file);
             // write to file
             create_task(FileIO::WriteTextAsync(file, file->Name)).then([ this , file]()
             {
                 // Let Windows know that we're finished changing the file so the other app can update the remote version of the file.
                 // Completing updates may require Windows to ask for user input.
                 create_task(CachedFileManager::CompleteUpdatesAsync(file)).then([ this , file](FileUpdateStatus status)
                 {
                     if  (status == FileUpdateStatus::Complete)
                     {
                         Display->Text = "File "  + file->Name + " was saved." ;
                     }
                     else
                     {
                         Display->Text = "File "  + file->Name + " couldn't be saved." ;
                     }
                 });
             });
         }
         else
         {
             Display->Text = "Operation cancelled." ;
         }
     });
}

 

 

 

 

 

 

 本文转自Work Hard Work Smart博客园博客,原文链接:http://www.cnblogs.com/linlf03/archive/2012/06/28/2567009.html,如需转载请自行联系原作者

 


目录
相关文章
|
1月前
|
Dart 前端开发
【05】flutter完成注册页面完善样式bug-增加自定义可复用组件widgets-严格规划文件和目录结构-规范入口文件-开发完整的社交APP-前端客户端开发+数据联调|以优雅草商业项目为例做开发-flutter开发-全流程-商业应用级实战开发-优雅草央千澈
【05】flutter完成注册页面完善样式bug-增加自定义可复用组件widgets-严格规划文件和目录结构-规范入口文件-开发完整的社交APP-前端客户端开发+数据联调|以优雅草商业项目为例做开发-flutter开发-全流程-商业应用级实战开发-优雅草央千澈
122 75
【05】flutter完成注册页面完善样式bug-增加自定义可复用组件widgets-严格规划文件和目录结构-规范入口文件-开发完整的社交APP-前端客户端开发+数据联调|以优雅草商业项目为例做开发-flutter开发-全流程-商业应用级实战开发-优雅草央千澈
|
4月前
|
移动开发 开发框架 小程序
uni-app:demo&媒体文件&配置全局的变量(三)
uni-app 是一个使用 Vue.js 构建多平台应用的框架,支持微信小程序、支付宝小程序、H5 和 App 等平台。本文档介绍了 uni-app 的基本用法,包括登录示例、媒体文件处理、全局变量配置和 Vuex 状态管理的实现。通过这些示例,开发者可以快速上手并高效开发多平台应用。
123 0
|
4月前
|
Linux 开发工具 数据安全/隐私保护
linux异常一:feng 不在 sudoers 文件中,此事将被报告。yum提示Another app is currently holding the yum lock; waiting for
这篇文章介绍了在CentOS 7系统中安装Docker时遇到的两个常见问题及其解决方法:用户不在sudoers文件中导致权限不足,以及yum被锁定的问题。
74 2
linux异常一:feng 不在 sudoers 文件中,此事将被报告。yum提示Another app is currently holding the yum lock; waiting for
|
4月前
|
Java Linux Apache
jar 解压app.jar到指定文件夹
要将 JAR 文件(如 `app.jar`)解压到指定文件夹,可使用 Java 自带的 `jar` 工具、Apache Ant、7-Zip 或 Python 脚本。方法包括命令行操作(如 `jar xf app.jar -C /path/to/destination/folder`)、Ant 构建文件、7-Zip 图形界面或命令行,以及 Python 的 `zipfile` 模块。选择适合的方法即可轻松完成解压。
320 3
|
6月前
|
JSON Linux 网络安全
【Azure 应用服务】如何从App Service for Linux 的环境中下载Container中非Home目录下的文件呢?
【Azure 应用服务】如何从App Service for Linux 的环境中下载Container中非Home目录下的文件呢?
|
6月前
|
API 网络架构
【Azure Logic App】在中国区的微软云服务上,使用逻辑应用是否可以下载SharePoint上的文件呢?
【Azure Logic App】在中国区的微软云服务上,使用逻辑应用是否可以下载SharePoint上的文件呢?
【Azure Logic App】在中国区的微软云服务上,使用逻辑应用是否可以下载SharePoint上的文件呢?
|
6月前
|
前端开发 JavaScript Linux
【Azure 应用服务】在Azure App Service for Linux环境中,部署的Django应用,出现加载css、js等静态资源文件失败
【Azure 应用服务】在Azure App Service for Linux环境中,部署的Django应用,出现加载css、js等静态资源文件失败
|
6月前
|
Java Linux 网络安全
【Azure 应用服务】App Service for Linux环境中,如何解决字体文件缺失的情况
【Azure 应用服务】App Service for Linux环境中,如何解决字体文件缺失的情况
|
21天前
|
前端开发 安全 开发工具
【11】flutter进行了聊天页面的开发-增加了即时通讯聊天的整体页面和组件-切换-朋友-陌生人-vip开通详细页面-即时通讯sdk准备-直播sdk准备-即时通讯有无UI集成的区别介绍-开发完整的社交APP-前端客户端开发+数据联调|以优雅草商业项目为例做开发-flutter开发-全流程-商业应用级实战开发-优雅草Alex
【11】flutter进行了聊天页面的开发-增加了即时通讯聊天的整体页面和组件-切换-朋友-陌生人-vip开通详细页面-即时通讯sdk准备-直播sdk准备-即时通讯有无UI集成的区别介绍-开发完整的社交APP-前端客户端开发+数据联调|以优雅草商业项目为例做开发-flutter开发-全流程-商业应用级实战开发-优雅草Alex
159 90
【11】flutter进行了聊天页面的开发-增加了即时通讯聊天的整体页面和组件-切换-朋友-陌生人-vip开通详细页面-即时通讯sdk准备-直播sdk准备-即时通讯有无UI集成的区别介绍-开发完整的社交APP-前端客户端开发+数据联调|以优雅草商业项目为例做开发-flutter开发-全流程-商业应用级实战开发-优雅草Alex
|
13天前
|
JavaScript 搜索推荐 Android开发
【01】仿站技术之python技术,看完学会再也不用去购买收费工具了-用python扒一个app下载落地页-包括安卓android下载(简单)-ios苹果plist下载(稍微麻烦一丢丢)-客户的麻将软件需要下载落地页并且要做搜索引擎推广-本文用python语言快速开发爬取落地页下载-优雅草卓伊凡
【01】仿站技术之python技术,看完学会再也不用去购买收费工具了-用python扒一个app下载落地页-包括安卓android下载(简单)-ios苹果plist下载(稍微麻烦一丢丢)-客户的麻将软件需要下载落地页并且要做搜索引擎推广-本文用python语言快速开发爬取落地页下载-优雅草卓伊凡
40 8
【01】仿站技术之python技术,看完学会再也不用去购买收费工具了-用python扒一个app下载落地页-包括安卓android下载(简单)-ios苹果plist下载(稍微麻烦一丢丢)-客户的麻将软件需要下载落地页并且要做搜索引擎推广-本文用python语言快速开发爬取落地页下载-优雅草卓伊凡

热门文章

最新文章

  • 1
    MNN-LLM App:在手机上离线运行大模型,阿里巴巴开源基于 MNN-LLM 框架开发的手机 AI 助手应用
  • 2
    原生鸿蒙版小艺APP接入DeepSeek-R1,为HarmonyOS应用开发注入新活力
  • 3
    【11】flutter进行了聊天页面的开发-增加了即时通讯聊天的整体页面和组件-切换-朋友-陌生人-vip开通详细页面-即时通讯sdk准备-直播sdk准备-即时通讯有无UI集成的区别介绍-开发完整的社交APP-前端客户端开发+数据联调|以优雅草商业项目为例做开发-flutter开发-全流程-商业应用级实战开发-优雅草Alex
  • 4
    【08】flutter完成屏幕适配-重建Android,增加GetX路由,屏幕适配,基础导航栏-多版本SDK以及gradle造成的关于fvm的使用(flutter version manage)-卓伊凡换人优雅草Alex-开发完整的社交APP-前端客户端开发+数据联调|以优雅草商业项目为例做开发-flutter开发-全流程-商业应用级实战开发-优雅草Alex
  • 5
    【Azure App Service】基于Linux创建的App Service是否可以主动升级内置的Nginx版本呢?
  • 6
    【Azure Function】Function App出现System.IO.FileNotFoundException异常
  • 7
    1688APP 原数据 API 接口的开发、应用与收益
  • 8
    PiliPala:开源项目真香,B站用户狂喜!这个开源APP竟能自定义主题+去广告?PiliPala隐藏功能大揭秘
  • 9
    APP-国内主流安卓商店-应用市场-鸿蒙商店上架之必备前提·全国公安安全信息评估报告如何申请-需要安全评估报告的资料是哪些-优雅草卓伊凡全程操作
  • 10
    语音app系统软件源码开发搭建新手启蒙篇
  • 1
    iOS|记一名 iOS 开发新手的前两次 App 审核经历
    10
  • 2
    2025同城线下陪玩APP开发/电竞游戏平台搭建游戏陪玩APP源码/语音APP开发
    17
  • 3
    flutter3-wetrip跨平台自研仿携程app预约酒店系统模板
    25
  • 4
    通过外部链接启动 Flutter App(详细介绍及示例)
    21
  • 5
    【03】仿站技术之python技术,看完学会再也不用去购买收费工具了-修改整体页面做好安卓下载发给客户-并且开始提交网站公安备案-作为APP下载落地页文娱产品一定要备案-包括安卓android下载(简单)-ios苹果plist下载(稍微麻烦一丢丢)-优雅草卓伊凡
    55
  • 6
    【02】仿站技术之python技术,看完学会再也不用去购买收费工具了-本次找了小影-感觉页面很好看-本次是爬取vue需要用到Puppeteer库用node.js扒一个app下载落地页-包括安卓android下载(简单)-ios苹果plist下载(稍微麻烦一丢丢)-优雅草卓伊凡
    46
  • 7
    【01】仿站技术之python技术,看完学会再也不用去购买收费工具了-用python扒一个app下载落地页-包括安卓android下载(简单)-ios苹果plist下载(稍微麻烦一丢丢)-客户的麻将软件需要下载落地页并且要做搜索引擎推广-本文用python语言快速开发爬取落地页下载-优雅草卓伊凡
    40
  • 8
    【Azure Function】Function App门户上的Test/Run返回错误:Failed to fetch
    36
  • 9
    小游戏源码开发之可跨app软件对接是如何设计和开发的
    42
  • 10
    原生鸿蒙版小艺APP接入DeepSeek-R1,为HarmonyOS应用开发注入新活力
    178