當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。