zoukankan      html  css  js  c++  java
  • File I/O in Windows Runtime GIS

    The following obtains a directory listing of all files in the documents folder:
    StorageFolder docsFolder = KnownFolders.DocumentsLibrary;
    IReadOnlyList<StorageFile> files = await docsFolder.GetFilesAsync();
    foreach (IStorageFile file in files)
    Debug.WriteLine (file.Name);

    The CreateFileQueryWithOptions method lets you filter to a specific extension:
    StorageFolder docsFolder = KnownFolders.DocumentsLibrary;
    var queryOptions = new QueryOptions (CommonFileQuery.DefaultQuery,
    new[] { ".txt" });
    var txtFiles = await docsFolder.CreateFileQueryWithOptions (queryOptions)
    .GetFilesAsync();
    foreach (StorageFile file in txtFiles)
    Debug.WriteLine (file.Name);

    The QueryOptions class exposes properties to further control the search. For example,
    the FolderDepth property requests a recursive directory listing:
    queryOptions.FolderDepth = FolderDepth.Deep;

    For example, the  following creates and writes to a file called test.txt in the documents folder:
    StorageFolder docsFolder = KnownFolders.DocumentsLibrary;
    StorageFile file = await docsFolder.CreateFileAsync
    ("test.txt", CreationCollisionOption.ReplaceExisting);
    using (Stream stream = await file.OpenStreamForWriteAsync())
    using (StreamWriter writer = new StreamWriter (stream))
    await writer.WriteLineAsync ("This is a test");
    If you don’t specify CreationCollisionOption.ReplaceExisting
    and the file already exists, it will automatically append a number
    to the filename to make it unique.
    The following reads the file back:
    StorageFolder docsFolder = KnownFolders.DocumentsLibrary;
    StorageFile file = await docsFolder.GetFileAsync ("test.txt");
    using (var stream = await file.OpenStreamForReadAsync ())
    using (StreamReader reader = new StreamReader (stream))
    Debug.WriteLine (await reader.ReadToEndAsync());

    Isolated Storage in Metro Apps Metro apps also have access to private folders that are isolated from other applications and can be used to store application-specific data:
    Windows.Storage.ApplicationData.Current.LocalFolder
    Windows.Storage.ApplicationData.Current.RoamingFolder
    Windows.Storage.ApplicationData.Current.TemporaryFolder
    Each of these static properties returns a StorageFolder object which can be used to read/write and list files as we described previously.

  • 相关阅读:
    Identity Server 4 从入门到落地(六)—— 简单的单页面客户端
    Identity Server 4 从入门到落地(十一)—— Docker部署
    C# 脚本
    网站迁移纪实:从Web Form 到 Asp.Net Core (Abp vNext 自定义开发)
    Identity Server 4 从入门到落地(七)—— 控制台客户端
    Robot Framework 使用总结
    Asp.Net Core 使用Monaco Editor 实现代码编辑器
    Identity Server 4 从入门到落地(五)—— 使用Ajax访问Web Api
    C# RabbitMQ的使用
    创建VS Code 扩展插件
  • 原文地址:https://www.cnblogs.com/gisbeginner/p/2671878.html
Copyright © 2011-2022 走看看