当前位置: 首页>>代码示例>>C#>>正文


C# StorageFolder.GetFileAsync方法代码示例

本文整理汇总了C#中Windows.Storage.StorageFolder.GetFileAsync方法的典型用法代码示例。如果您正苦于以下问题:C# StorageFolder.GetFileAsync方法的具体用法?C# StorageFolder.GetFileAsync怎么用?C# StorageFolder.GetFileAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Windows.Storage.StorageFolder的用法示例。


在下文中一共展示了StorageFolder.GetFileAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LoadFile

        /// <summary>
        /// Loads file from path
        /// </summary>
        /// <param name="filepath">path to a file</param>
        /// <param name="folder">folder or null (to load from application folder)</param>
        /// <returns></returns>
        protected XDocument LoadFile(string filepath, StorageFolder folder)
        {
            try
            {
                StorageFile file;

                //load file
                if (folder == null)
                {
                    var uri = new Uri(filepath);
                    file = StorageFile.GetFileFromApplicationUriAsync(uri).AsTask().ConfigureAwait(false).GetAwaiter().GetResult();
                }
                else
                {
                    file = folder.GetFileAsync(filepath).AsTask().ConfigureAwait(false).GetAwaiter().GetResult();
                }

                //parse and return
                var result = FileIO.ReadTextAsync(file).AsTask().ConfigureAwait(false).GetAwaiter().GetResult();
                return XDocument.Parse(result);
            }
            catch
            {
                return null;
            }
        }
开发者ID:Syanne,项目名称:Holiday-Calendar,代码行数:32,代码来源:BasicDataResource.cs

示例2: GetCachedUserPreference

 public async Task< string> GetCachedUserPreference()
 {
     roamingFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
     StorageFile file = await roamingFolder.GetFileAsync(filename);
     string response = await FileIO.ReadTextAsync(file);
     return response;
 }
开发者ID:hasans30,项目名称:TransInfo,代码行数:7,代码来源:TransLinkService.cs

示例3: loadTextFile

        public async Task<string> loadTextFile(StorageFolder folder, string key = null)
        {
            StorageFile myFile;
            try
            {
                if (key == null)
                {
                    myFile = await folder.GetFileAsync("myData.txt");
                }
                else
                {
                    myFile = await folder.GetFileAsync(key + ".txt");
                }
            }
            catch
            {
                myFile = null;
            }

            string text = "";
            if (myFile != null)
            {
                text = await FileIO.ReadTextAsync(myFile);
            }

            return text;
        }
开发者ID:huang-lu,项目名称:Universal-App-MVVM,代码行数:27,代码来源:StorageService.cs

示例4: GetFileAsync

        /// <summary>
        /// Gets File located in Local Storage,
        /// Input file name may include folder paths seperated by "\\".
        /// Example: filename = "Documentation\\Tutorial\\US\\ENG\\version.txt"
        /// </summary>
        /// <param name="filename">Name of file with full path.</param>
        /// <param name="rootFolder">Parental folder.</param>
        /// <returns>Target StorageFile.</returns>
        public async Task<StorageFile> GetFileAsync(string filename, StorageFolder rootFolder = null)
        {
            if (string.IsNullOrEmpty(filename))
            {
                return null;
            }

            var semaphore = GetSemaphore(filename);
            await semaphore.WaitAsync();

            try
            {
                rootFolder = rootFolder ?? AntaresBaseFolder.Instance.RoamingFolder;
                return await rootFolder.GetFileAsync(NormalizePath(filename));
            }
            catch (Exception ex)
            {
                LogManager.Instance.LogException(ex.ToString());
                return null;
            }
            finally
            {
                semaphore.Release();
            }
        }
开发者ID:nghia2080,项目名称:CProject,代码行数:33,代码来源:FileStorageAdapter.cs

示例5: GetFile

 // Working
 /// <summary>
 /// Gets a file from the file system.
 /// </summary>
 /// <param name="folder">The folder that contains the file.</param>
 /// <param name="fileName">Name of the file.</param>
 /// <returns>The file if it exists, null otherwise.</returns>
 public static StorageFile GetFile(StorageFolder folder, string fileName)
 {
     try
     {
         return folder.GetFileAsync(fileName).AsTask().Result;
     }
     catch (Exception)
     {
         return null;
     }
 }
开发者ID:molant,项目名称:MangApp,代码行数:18,代码来源:FileSystemUtilities.cs

示例6: CopyNecessaryFilesFromCurrentPackage

 internal async static Task CopyNecessaryFilesFromCurrentPackage(StorageFile diffManifestFile, StorageFolder currentPackageFolder, StorageFolder newPackageFolder)
 {
     await FileUtils.MergeFolders(currentPackageFolder, newPackageFolder);
     JObject diffManifest = await CodePushUtils.GetJObjectFromFile(diffManifestFile);
     var deletedFiles = (JArray)diffManifest["deletedFiles"];
     foreach (string fileNameToDelete in deletedFiles)
     {
         StorageFile fileToDelete = await newPackageFolder.GetFileAsync(fileNameToDelete);
         await fileToDelete.DeleteAsync();
     }
 }
开发者ID:cmcewen,项目名称:react-native-code-push,代码行数:11,代码来源:UpdateUtils.cs

示例7: copyToLocal

        //-------------------------------------------------------------------------------
        #region +[static]copyToLocal 選択フォルダからローカルへコピー
        //-------------------------------------------------------------------------------
        //
        public async static void copyToLocal(StorageFolder rootDir, Action<int, int, int, int> progressReportFunc = null) {
            var localDir = Windows.Storage.ApplicationData.Current.LocalFolder;
            var dataDir_dst = await localDir.CreateFolderAsync(DATA_FOLDER_NAME, CreationCollisionOption.OpenIfExists);
            var dataDir_src = await rootDir.GetFolderAsync("CDATA");

            var fileList = await dataDir_src.GetFilesAsync(Windows.Storage.Search.CommonFileQuery.DefaultQuery);

            if (progressReportFunc != null) { progressReportFunc(0, 2, 0, fileList.Count); }

            int count = 0;
            foreach (var file in fileList) {
                await file.CopyAsync(dataDir_dst, file.Name, NameCollisionOption.ReplaceExisting);
                count++;
                if (progressReportFunc != null) { progressReportFunc(0, 2, count, fileList.Count); }
            }

            var imageDir = await localDir.CreateFolderAsync(IMAGES_FOLDER_NAME, CreationCollisionOption.OpenIfExists);

            var imgFile = await rootDir.GetFileAsync("C084CUTL.CCZ");
            MemoryStream ms = new MemoryStream();
            using (Stream stream = (await imgFile.OpenReadAsync()).AsStream()) {
                byte[] buf = new byte[0x10000000];
                while (true) {
                    int r = stream.Read(buf, 0, buf.Length);
                    if (r <= 0) { break; }
                    ms.Write(buf, 0, r);
                }
            }
            var zipArchive = new ZipArchive(ms);

            if (progressReportFunc != null) { progressReportFunc(1, 2, 0, zipArchive.Entries.Count); }
            count = 0;

            foreach (var entry in zipArchive.Entries) {
                string name = entry.Name;
                using (Stream dstStr = await imageDir.OpenStreamForWriteAsync(name, CreationCollisionOption.ReplaceExisting))
                using (Stream srcStr = entry.Open()) {
                    int size;
                    const int BUF_SIZE = 0x100000;
                    byte[] buf = new byte[BUF_SIZE];
                    size = srcStr.Read(buf, 0, BUF_SIZE);
                    while (size > 0) {
                        dstStr.Write(buf, 0, size);
                        size = srcStr.Read(buf, 0, BUF_SIZE);
                    }
                    count++;
                    if (progressReportFunc != null) { progressReportFunc(1, 2, count, zipArchive.Entries.Count); }
                }
            }
            if (progressReportFunc != null) { progressReportFunc(2, 2, count, zipArchive.Entries.Count); }

            ms.Dispose();
            zipArchive.Dispose();
        }
开发者ID:kavenblog,项目名称:ComicStarViewer,代码行数:58,代码来源:コピー+~+CatalogData.cs

示例8: ValidateFile

 /// <summary>
 ///     Check to see if the file exists or not
 /// </summary>
 /// <param name="storagefolder">StorageFolder</param>
 /// <param name="filename">string</param>
 /// <returns>StorageFile or null</returns>
 public static async Task<StorageFile> ValidateFile(StorageFolder storagefolder, string filename)
 {
     try
     {
         return await storagefolder.GetFileAsync(filename);
     }
     catch (FileNotFoundException)
     {
         return null;
     }
 }
开发者ID:jhondoe404,项目名称:project_f,代码行数:17,代码来源:FileHelper.cs

示例9: Launch

        public static async Task<bool> Launch(string filename, StorageFolder folder)
        {
            IStorageFile file = await folder.GetFileAsync(filename);

            LauncherOptions options = new LauncherOptions();
            //options.DisplayApplicationPicker = true;
            //options.FallbackUri = GetUri(cole_protocol);

            bool result = await Launcher.LaunchFileAsync(file, options);
            return result;
        }
开发者ID:Captwalloper,项目名称:FlawlessCowboy,代码行数:11,代码来源:FileHelper.cs

示例10: FileExists

        private static bool FileExists(StorageFolder folder, string fileName)
        {
            try
            {
                var task = folder.GetFileAsync(fileName).AsTask();

                task.Wait();
                
                return true;
            }
            catch { return false; }
        }
开发者ID:TheMouster,项目名称:coolstorage,代码行数:12,代码来源:CS.cs

示例11: DoesFileExistAsync

 public static async Task<bool> DoesFileExistAsync(StorageFile file, StorageFolder folder, string fileName)
 {
     try
     {
         file = await folder.GetFileAsync(fileName);
         return true;
     }
     catch
     {
         return false;
     }
 }
开发者ID:yjlintw,项目名称:YJToolkit,代码行数:12,代码来源:FileIO.cs

示例12: fileExistAsync

 //public static async Task<bool> fileExistAsync(StorageFolder folder, string fileName)
 public static async Task<bool> fileExistAsync(StorageFolder folder, string fileName)
 {
     try
     {
         await folder.GetFileAsync(fileName);
         return true;
     }
     catch( Exception e )
     {
         return false;
     }
 }
开发者ID:rkrishnasanka,项目名称:windows8,代码行数:13,代码来源:Utils.cs

示例13: DoesFileExistAsync

 public static async Task<bool> DoesFileExistAsync(StorageFolder folder, string filename)
  {
      var folders = (await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFoldersAsync()).To‌​List();
      try
      {
          await folder.GetFileAsync(filename);
          return true;
      }
      catch
      {
          return false;
      }
  }
开发者ID:fedorinoGore,项目名称:bookScriptorW10,代码行数:13,代码来源:EpubReader.cs

示例14: Setup

        public async void Setup()
        {
            Folder = ApplicationData.Current.LocalFolder;


            //połącz do pliku jesli istnieje
            try
            {
                File = await Folder.GetFileAsync("json.txt");
            }
            //utwórz gdy go nie ma
            catch
            {
                File = await Folder.CreateFileAsync("json.txt");
            }
        }
开发者ID:pozzzima123,项目名称:TcpListenerRTM,代码行数:16,代码来源:LoggingTxt.cs

示例15: IsFileExists

 /// <summary>
 /// Checks if a file exists into the <see cref="StorageFolder"/>
 /// </summary>
 /// <param name="storageFolder">the folder where the function has to check</param>
 /// <param name="fileName">the name of the file</param>
 /// <returns>true if the file exists, false otherwise</returns>
 public async Task<bool> IsFileExists(StorageFolder storageFolder, string fileName)
 {
   using (await InstanceLock.LockAsync())
   {
     try
     {
       fileName = fileName.Replace("/", "\\");
       var file = await storageFolder.GetFileAsync(fileName);
       return (file != null);
     }
     catch
     {
       return false;
     }
   }
 }
开发者ID:smartnsoft,项目名称:ModernApp4Me,代码行数:22,代码来源:M4MFilePersistence.cs


注:本文中的Windows.Storage.StorageFolder.GetFileAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。