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


C# StorageFolder.TryGetItemAsync方法代码示例

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


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

示例1: LoadAsync

 public async static Task LoadAsync(this InkCanvas inkCanvas, string fileName, StorageFolder folder = null)
 {
     folder = folder ?? ApplicationData.Current.TemporaryFolder;
     var file = await folder.TryGetItemAsync(fileName) as StorageFile;
     if (file != null)
     {
         try
         {
             using (var stream = await file.OpenSequentialReadAsync())
             {
                 await inkCanvas.InkPresenter.StrokeContainer.LoadAsync(stream);
             }
         }
         catch { }
     }
 }
开发者ID:teamneusta,项目名称:Template10,代码行数:16,代码来源:InkUtils.cs

示例2: DeleteFolder

        /// <summary>
        /// Deletes folder even if it contains read only files
        /// </summary>
        /// <param name="path"></param>
        public async static Task<bool> DeleteFolder(StorageFolder baseDir, string path)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                return false;
            }

            var folder = await baseDir.TryGetItemAsync(path) as StorageFolder;
            if (folder == null)
            {
                return false;
            }

            foreach (var file in await folder.GetFilesAsync())
            {
                await SafeFileDelete(file.Path);
            }
            await folder.DeleteAsync();
            return true;
        }
开发者ID:hubaishan,项目名称:quran-phone,代码行数:24,代码来源:FileUtils.cs

示例3: OpenComicCollection

       private async void OpenComicCollection(StorageFolder chosenFolder, StorageFolder collections)
       {
           LoadingGridVisible(true);
           List<StorageFile> files = await RecursivelySearchForFiles(chosenFolder);
           StorageFolder collectionFolder = (StorageFolder)await collections.TryGetItemAsync(chosenFolder.Name);
           if (collectionFolder == null)
           {
               collectionFolder = await collections.CreateFolderAsync(chosenFolder.Name);
           }
           else
           {
               ShowWarning("Collection already exist!", "Adding new comics");
           }

           foreach (StorageFile sourceFile in files)
           {
               StorageFolder destFolder = (StorageFolder)await collectionFolder.TryGetItemAsync(sourceFile.Name);
               if (destFolder == null)
               {
                   destFolder = await collectionFolder.CreateFolderAsync(sourceFile.Name);
                   try
                   {
                       DefaultViewModel["LoadingFile"] = sourceFile.Name;
                       if (sourceFile.FileType.Equals("cbz") || sourceFile.FileType.Equals(".cbz"))
                           await FolderZip.UnZipFile(sourceFile, destFolder);
                       else if (sourceFile.FileType.Equals("cbr") || sourceFile.FileType.Equals(".cbr"))
                           await FolderZip.UnRarFile(sourceFile, destFolder);
                   }
                   catch (InvalidFormatException exception)
                   {
                       ShowWarning("Error opening file:" + sourceFile.Name, "Please try again");
                   }
               }
               LoadingBar.Value += (1.0 / files.Count()) * 100;
           }

           await CreateCollectionTiles();
           CollectionViews.Clear();
           foreach (CollectionTile tile in CollectionTiles)
           {
               CollectionViews.Add(new CollectionView(tile));
           }
           defaultViewModel["ComicTiles"] = ComicTiles;
           defaultViewModel["CollectionViews"] = CollectionViews;
           LoadingGridVisible(false);
       }
开发者ID:emptyflash,项目名称:ComicViewer,代码行数:46,代码来源:MainPage.xaml.cs

示例4: ContinueAfterExportBinderPickerAsync

		private async Task ContinueAfterExportBinderPickerAsync(StorageFolder toDir, string dbName, Briefcase bc)
		{
			bool isExported = false;
			try
			{
				if (bc != null && toDir != null)
				{
					_animationStarter.StartAnimation(AnimationStarter.Animations.Updating);

					if (string.IsNullOrWhiteSpace(dbName) /*|| _dbNames?.Contains(dbName) == false */|| toDir == null) return;

					var fromDirectory = await Briefcase.BindersDirectory
						.GetFolderAsync(dbName)
						.AsTask().ConfigureAwait(false);
					if (fromDirectory == null) return;
					// what if you copy a directory to an existing one? Shouldn't you delete the contents first? No! But then, shouldn't you issue a warning?
					var toDirectoryTest = await toDir.TryGetItemAsync(dbName).AsTask().ConfigureAwait(false);
					if (toDirectoryTest != null)
					{
						var confirmation =
							await UserConfirmationPopup.GetInstance().GetUserConfirmationBeforeExportingBinderAsync(CancToken).ConfigureAwait(false);
						if (CancToken.IsCancellationRequested) return;
						if (confirmation == null || confirmation.Item1 == false || confirmation.Item2 == false) return;
					}

					isExported = await bc.ExportBinderAsync(dbName, fromDirectory, toDir).ConfigureAwait(false);
				}
			}
			catch (Exception ex)
			{
				await Logger.AddAsync(ex.ToString(), Logger.FileErrorLogFilename, Logger.Severity.Info).ConfigureAwait(false);
			}
			finally
			{
				_animationStarter.EndAllAnimations();
				if (!CancToken.IsCancellationRequested)
					_animationStarter.StartAnimation(isExported
						? AnimationStarter.Animations.Success
						: AnimationStarter.Animations.Failure);

				IsExportingBinder = false;
			}
		}
开发者ID:lolluslollus,项目名称:UniFiler10,代码行数:43,代码来源:BriefcaseVM.cs

示例5: FileDoesNotExistAsync

 private static async Task<bool> FileDoesNotExistAsync(string fileName, StorageFolder imagesFolder)
 {
     return await imagesFolder.TryGetItemAsync(fileName) == null;
 }
开发者ID:michaellperry,项目名称:Commuter,代码行数:4,代码来源:ImageCacheCell.cs

示例6: initialize

        //Initialize "devices" list and Channel and volumeDevices
        public async Task initialize(StorageFolder devices_folder_)
        {
            is_initialized = true;
            // Device Manager Metadata Initialization 
            devices_folder = devices_folder_;
            devices_info_file = (StorageFile) await devices_folder.TryGetItemAsync("devices_info.txt");
            if(devices_info_file == null)
            {
                System.Diagnostics.Debug.WriteLine("No Devices info file!");
                return;
            }
            IList<string> input = await FileIO.ReadLinesAsync(devices_info_file);
            int num_channel_devices = Convert.ToInt32(input[0]);
            int cur_index = 1;
            String device_name;
            StorageFile cur_device_input_file;

            // Channel Device Initialization

            for(int i = 0; i < num_channel_devices; ++i)
            {
                device_name = input[cur_index++];
                try
                {
                    cur_device_input_file = (StorageFile)await get_input_file_from_name(device_name, 'c');
                    ChannelDevice c_device = new ChannelDevice(device_name, cur_device_input_file);
                    channel_devices.Add(c_device);
                }
                catch(Exception except)
                {
                    System.Diagnostics.Debug.WriteLine(except.Message);
                }
            }
            // Get Current Channel Device
            int chan_index = 0;
            bool found = false;
            string cur_chan_device_name = input[cur_index++];
            foreach(ChannelDevice cur in channel_devices)
            {
                if(cur.get_name().Equals(cur_chan_device_name))
                {
                    found = true;
                    break;
                }
                chan_index++;
            }
            if (!found)
            {
                // Throw Exception about channel device not found
            }
            else
            {
                channelController = channel_devices[chan_index];
                await channelController.initialize();
            }

            // Volume Device Initialization

            int num_vol_devices = Convert.ToInt32(input[cur_index++]);
            for(int i = 0; i < num_vol_devices; ++i)
            {
                device_name = input[cur_index++];
                cur_device_input_file = await get_input_file_from_name(device_name, 'v');
                VolumeDevice v_device = new VolumeDevice(device_name, cur_device_input_file);
                volume_devices.Add(v_device);
            }
            int vol_index = 0;
            string cur_vol_device_name = input[cur_index++];
            found = false;
            foreach(VolumeDevice cur_v in volume_devices)
            {
                if(cur_v.get_name().Equals(cur_vol_device_name))
                {
                    found = true;
                    break;
                }
                vol_index++;
            }
            if(!found)
            {
                // TODO: Throw Error
            }
            else
            {
                volumeController = volume_devices[vol_index];
                await volumeController.initialize();
            }
      
        }
开发者ID:jessupjn,项目名称:CPRemote,代码行数:90,代码来源:DeviceManager.cs

示例7: DirectoryExists

 public static async Task<bool> DirectoryExists(StorageFolder baseDir, string path)
 {
     try
     {
         return (await baseDir.TryGetItemAsync(path)) != null;
     }
     catch (FileNotFoundException)
     {
         return false;
     }
 }
开发者ID:hubaishan,项目名称:quran-phone,代码行数:11,代码来源:FileUtils.cs

示例8: FileExists

        public static async Task<bool> FileExists(StorageFolder baseFolder, string fileName)
        {
            if (baseFolder == null || string.IsNullOrWhiteSpace(fileName))
            {
                return false;
            }

            try
            {
                var storageItem = await baseFolder.TryGetItemAsync(fileName);
                return storageItem != null && storageItem.IsOfType(StorageItemTypes.File);
            }
            catch (Exception)
            {
                return false;
            }
        }
开发者ID:hubaishan,项目名称:quran-phone,代码行数:17,代码来源:FileUtils.cs

示例9: GetFile

        public static async Task<StorageFile> GetFile(StorageFolder folder, string path)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                return null;
            }

            try
            {
                return await folder.TryGetItemAsync(Path.GetFileName(path)) as StorageFile;
            }
            catch (Exception)
            {
                return null;
            }
        }
开发者ID:hubaishan,项目名称:quran-phone,代码行数:16,代码来源:FileUtils.cs

示例10: IfFolderExistsAsync

 /// <summary> 
 /// It checks if the specified folder exists. 
 /// </summary> 
 /// <param name="storageFolder">The container folder</param> 
 /// <param name="subFolderName">The sub folder name</param> 
 /// <returns></returns> 
 private static async Task<bool> IfFolderExistsAsync(StorageFolder storageFolder, string subFolderName)
 {
     var storageItem = await storageFolder.TryGetItemAsync(subFolderName);
     return storageItem != null && storageItem.IsOfType(StorageItemTypes.Folder);
 }
开发者ID:hubaishan,项目名称:quran-phone,代码行数:11,代码来源:CompressionUtils.cs

示例11: IfStorageItemExist

 public async Task<bool> IfStorageItemExist(StorageFolder folder, string itemName)
 {
     try
     {
         IStorageItem item = await folder.TryGetItemAsync(itemName);
         return (item != null);
     }
     catch (Exception)
     {
         // Should never get here 
         return false;
     }
 } 
开发者ID:jessupjn,项目名称:CPRemote,代码行数:13,代码来源:AddNewChannelPopup.xaml.cs

示例12: _GetFolderAsync

 private static async Task<StorageFolder> _GetFolderAsync(string name, StorageFolder parent)
 {
     var item = await parent.TryGetItemAsync(name).AsTask().DontMarshall();
     return item as StorageFolder;
 }
开发者ID:haroldma,项目名称:Audiotica,代码行数:5,代码来源:StorageHelper.cs

示例13: GetIfFileExistsAsync

        public static async Task<StorageFile> GetIfFileExistsAsync(string path, StorageFolder folder)
        {
            var parts = path.Split('/');

            var fileName = parts.Last();

            if (parts.Length > 1)
            {
                folder =
                    await GetFolderAsync(path.Substring(0, path.Length - fileName.Length), folder).ConfigureAwait(false);
            }

            if (folder == null)
            {
                return null;
            }
            return await folder.TryGetItemAsync(fileName).AsTask().DontMarshall() as StorageFile;
        }
开发者ID:haroldma,项目名称:Audiotica,代码行数:18,代码来源:StorageHelper.cs

示例14: _GetFolderAsync

 private static async Task<StorageFolder> _GetFolderAsync(string name, StorageFolder parent)
 {
     var item = await parent.TryGetItemAsync(name).AsTask().ConfigureAwait(false);
     return item as StorageFolder;
 }
开发者ID:haroldma,项目名称:Universal.Torrent,代码行数:5,代码来源:StorageHelper.cs


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