• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Storage.StorageFolder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



StorageFolder类属于Windows.Storage命名空间,在下文中一共展示了StorageFolder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: Init

        async Task Init()
        {
            if (isInitialized != null)
                return;

            cacheFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(cacheFolderName, CreationCollisionOption.OpenIfExists);

            try
            {
                isInitialized = InitializeWithJournal();
                await isInitialized;
            }
            catch
            {
                StorageFolder folder = null;

                try
                {
                    folder = await ApplicationData.Current.LocalFolder.GetFolderAsync(cacheFolderName);
                }
                catch (Exception)
                {
                }

                if (folder != null)
                {
                    await folder.DeleteAsync();
                    await ApplicationData.Current.LocalFolder.CreateFolderAsync(cacheFolderName, CreationCollisionOption.ReplaceExisting);
                }
            }

            await CleanCallback();
        }
开发者ID:zenjoy,项目名称:FFImageLoading,代码行数:33,代码来源:DiskCache.cs


示例3: SaveAsync

        /// <summary>
        /// Writes a string to a text file.
        /// </summary>
        /// <param name="text">The text to write.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="folder">The folder.</param>
        /// <param name="options">
        /// The enum value that determines how responds if the fileName is the same
        /// as the name of an existing file in the current folder. Defaults to ReplaceExisting.
        /// </param>
        /// <returns></returns>
        public static async Task SaveAsync(
            this string text,
            string fileName,
            StorageFolder folder = null,
            CreationCollisionOption options = CreationCollisionOption.ReplaceExisting)
        {
            folder = folder ?? ApplicationData.Current.LocalFolder;
            var file = await folder.CreateFileAsync(
                fileName,
                options);
            using (var fs = await file.OpenAsync(FileAccessMode.ReadWrite))
            {
                using (var outStream = fs.GetOutputStreamAt(0))
                {
                    using (var dataWriter = new DataWriter(outStream))
                    {
                        if (text != null)
                            dataWriter.WriteString(text);

                        await dataWriter.StoreAsync();
                        dataWriter.DetachStream();
                    }

                    await outStream.FlushAsync();
                }
            }
        }
开发者ID:xyzzer,项目名称:WinRTXamlToolkit,代码行数:38,代码来源:StringIOExtensions.cs


示例4: LimitedStorageCache

 /// <summary>
 /// Creates new LimitedStorageCache instance
 /// </summary>
 /// <param name="isf">StorageFolder instance to work with file system</param>
 /// <param name="cacheDirectory">Directory to store cache, starting with two slashes "\\"</param>
 /// <param name="cacheFileNameGenerator">ICacheFileNameGenerator instance to generate cache filenames</param>
 /// <param name="cacheLimitInBytes">Limit of total cache size in bytes, for example 10 mb == 10 * 1024 * 1024</param>
 /// <param name="cacheMaxLifetimeInMillis">Cache max lifetime in millis, for example two weeks = 2 * 7 * 24 * 60 * 60 * 1000; default value == one week; pass value &lt;= 0 to disable max cache lifetime</param>
 public LimitedStorageCache(StorageFolder isf, string cacheDirectory,
     ICacheGenerator cacheFileNameGenerator, long cacheLimitInBytes, long cacheMaxLifetimeInMillis = DefaultCacheMaxLifetimeInMillis)
     : base(isf, cacheDirectory, cacheFileNameGenerator, cacheMaxLifetimeInMillis)
 {
     _cacheLimitInBytes = cacheLimitInBytes;
     BeginCountCurrentCacheSize();
 }
开发者ID:chenrensong,项目名称:ImageLib.UWP,代码行数:15,代码来源:LimitedStorageCache.cs


示例5: 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


示例6: GetAllVideos

        private async void GetAllVideos(StorageFolder KnownFolders, QueryOptions QueryOptions)
        {
            StorageFileQueryResult query = KnownFolders.CreateFileQueryWithOptions(QueryOptions);
            IReadOnlyList<StorageFile> folderList = await query.GetFilesAsync();

            // Get all the videos in the folder past in parameter
            int id = 0;
            foreach (StorageFile file in folderList)
            {
                using (StorageItemThumbnail thumbnail = await file.GetThumbnailAsync(ThumbnailMode.VideosView, 200, ThumbnailOptions.UseCurrentScale))
                {
                    // Get video's properties
                    VideoProperties videoProperties = await file.Properties.GetVideoPropertiesAsync();

                    BitmapImage VideoCover = new BitmapImage();
                    VideoCover.SetSource(thumbnail);

                    Video video = new Video();
                    video.Id = id;
                    video.Name = file.Name;
                    video.DateCreated = file.DateCreated.UtcDateTime;
                    video.FileType = file.FileType;
                    video.VideoPath = file.Path;
                    video.Duration = videoProperties.Duration;
                    video.VideoFile = file;
                    video.VideoCover = VideoCover;

                    // Add the video to the ObservableCollection
                    Videos.Add(video);
                    id++;
                }
            }
        }
开发者ID:zirakai,项目名称:NyxoWp,代码行数:33,代码来源:GetVideos.cs


示例7: Inflate

        private static async Task Inflate(StorageFile zipFile, StorageFolder destFolder)
        {
            if (zipFile == null)
            {
                throw new Exception("StorageFile (zipFile) passed to Inflate is null");
            }
            else if (destFolder == null)
            {
                throw new Exception("StorageFolder (destFolder) passed to Inflate is null");
            }

            Stream zipStream = await zipFile.OpenStreamForReadAsync();

            using (ZipArchive zipArchive = new ZipArchive(zipStream, ZipArchiveMode.Read))
            {
                //Debug.WriteLine("Count = " + zipArchive.Entries.Count);
                foreach (ZipArchiveEntry entry in zipArchive.Entries)
                {
                    //Debug.WriteLine("Extracting {0} to {1}", entry.FullName, destFolder.Path);
                    try
                    {
                        await InflateEntryAsync(entry, destFolder);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine("Exception: " + ex.Message);
                    }
                }
            }
        }
开发者ID:Pixelchain,项目名称:lora,代码行数:30,代码来源:PGZipInflate.cs


示例8: GetPictures

        public GetPictures(StorageFolder folder)
        {
            Pictures = new ObservableCollection<Picture>();
            allPictures = new ObservableCollection<StorageFile>();

            GetAllPictures(folder);
        }
开发者ID:zirakai,项目名称:NyxoWp,代码行数:7,代码来源:GetPictures.cs


示例9: GetFiles

        public async Task<IEnumerable<IFile>> GetFiles()
        {
            if (m_files == null)
            {
                m_files = new List<IFile>();
                foreach (StorageFile file in await m_folder.GetFilesAsync())
                {
                    //don't ping the network
                    //make the configurable later
                    if (!file.Attributes.HasFlag(FileAttributes.LocallyIncomplete))
                    {
                        IFile f = await File.GetNew(file, m_root);
                        m_files.Add(f);
                    }
                }
            }

            //we want to clear out the StorageFolder so that it can be 
            //garbage collected after both the files and directories
            //have been retrieved
            if (m_dirs != null)
            {
                m_folder = null;
            }

            return m_files;
        }
开发者ID:hoangduit,项目名称:ndupfinder,代码行数:27,代码来源:Directory.cs


示例10: Directory

        public Directory(StorageFolder folder, StorageFolder root)
        {
            m_folder = folder;
            m_root = root;

            m_path = folder.Path;
        }
开发者ID:hoangduit,项目名称:ndupfinder,代码行数:7,代码来源:Directory.cs


示例11: Init

        async Task Init()
        {
            try
            {
                cacheFolder = await ApplicationData.Current.TemporaryFolder.CreateFolderAsync(cacheFolderName, CreationCollisionOption.OpenIfExists);
                await InitializeEntries().ConfigureAwait(false);
            }
            catch
            {
                StorageFolder folder = null;

                try
                {
                    folder = await ApplicationData.Current.LocalFolder.GetFolderAsync(cacheFolderName);
                }
                catch (Exception)
                {
                }

                if (folder != null)
                {
                    await folder.DeleteAsync();
                    await ApplicationData.Current.LocalFolder.CreateFolderAsync(cacheFolderName, CreationCollisionOption.ReplaceExisting);
                }
            }
            finally
            {
                var task = CleanCallback();
            }
        }
开发者ID:CaLxCyMru,项目名称:FFImageLoading,代码行数:30,代码来源:SimpleDiskCache.cs


示例12: FileSnapshotTarget

        static FileSnapshotTarget()
        {
            // create a task to load the folder...
            _setupTask = Task<Task<StorageFolder>>.Factory.StartNew(async () =>
            {
                // get...
                var root = ApplicationData.Current.LocalFolder;
                try
                {
                    await root.CreateFolderAsync(LogFolderName);
                }
                catch (FileNotFoundException ex)
                {
                    SinkException(ex);
                }

                // load...
                return await root.GetFolderAsync(LogFolderName);

            }).ContinueWith(async (t, args) =>
            {
                // set...
                LogFolder = await t.Result;

            }, TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.LongRunning);
        }
开发者ID:Erls-Corporation,项目名称:ProgrammingMetroStyle,代码行数:26,代码来源:FileSnapshotTarget.cs


示例13: FileDbCache

        public FileDbCache(string name = null, StorageFolder folder = null)
        {
            if (string.IsNullOrEmpty(name))
            {
                name = TileImageLoader.DefaultCacheName;
            }

            if (string.IsNullOrEmpty(Path.GetExtension(name)))
            {
                name += ".fdb";
            }

            if (folder == null)
            {
                folder = TileImageLoader.DefaultCacheFolder;
            }

            this.folder = folder;
            this.name = name;

            Application.Current.Resuming += async (s, e) => await Open();
            Application.Current.Suspending += (s, e) => Close();

            var task = Open();
        }
开发者ID:huoxudong125,项目名称:XamlMapControl,代码行数:25,代码来源:FileDbCache.cs


示例14: UnZipFile

        async public static Task UnZipFile(StorageFolder zipFileDirectory, string zipFilename, StorageFolder extractFolder = null)
        {
            if (extractFolder == null) extractFolder = zipFileDirectory;

            var folder = ApplicationData.Current.LocalFolder;

            using (var zipStream = await folder.OpenStreamForReadAsync(zipFilename))
            {
                using (MemoryStream zipMemoryStream = new MemoryStream((int)zipStream.Length))
                {
                    await zipStream.CopyToAsync(zipMemoryStream);

                    using (var archive = new ZipArchive(zipMemoryStream, ZipArchiveMode.Read))
                    {
                        foreach (ZipArchiveEntry entry in archive.Entries)
                        {
                            if (entry.Name != "")
                            {
                                using (Stream fileData = entry.Open())
                                {
                                    StorageFile outputFile = await extractFolder.CreateFileAsync(entry.FullName, CreationCollisionOption.ReplaceExisting);
                                    using (Stream outputFileStream = await outputFile.OpenStreamForWriteAsync())
                                    {
                                        await fileData.CopyToAsync(outputFileStream);
                                        await outputFileStream.FlushAsync();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
开发者ID:vulcanlee,项目名称:Windows8Lab,代码行数:33,代码来源:FolderZip.cs


示例15: LoadAsync

        public static async Task<BitmapImage> LoadAsync(StorageFolder folder, string fileName)
        {
            BitmapImage bitmap = new BitmapImage();

            var file = await folder.GetFileByPathAsync(fileName);
            return await bitmap.SetSourceAsync(file);
        }
开发者ID:chao-zhou,项目名称:PomodoroTimer,代码行数:7,代码来源:BitmapImageLoadExtensions.cs


示例16: WindowsIsolatedStorage

		public WindowsIsolatedStorage(StorageFolder folder)
		{
			if (folder == null)
				throw new ArgumentNullException("folder");

			_folder = folder;
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:7,代码来源:WindowsIsolatedStorage.cs


示例17: UnzipFromStorage

 public static async Task UnzipFromStorage(StorageFile pSource, StorageFolder pDestinationFolder, IEnumerable<string> pIgnore)
 {
     using (var stream = await pSource.OpenStreamForReadAsync())
     {
         await UnzipFromStream(stream, pDestinationFolder,pIgnore.ToList());
     }
 }
开发者ID:bigfool,项目名称:WPTelnetD,代码行数:7,代码来源:ZipHelper.cs


示例18: GetNewFileName

        /// <summary>
        /// Gets a new filename which starts as the base filename parameter, but has a different end part.
        /// </summary>
        /// <param name="folder">The folder where the name will be checked.</param>
        /// <param name="baseFileName">Base filename to use as root.</param>
        /// <returns>
        /// The new filename.
        /// </returns>
        /// <example>
        /// In case that "naruto" does not exist in folder.
        /// GetNewFileName(folder, "naruto") -&gt; "naruto"
        /// GetNewFileName(folder, "naruto") -&gt; "naruto_1"
        /// GetNewFileName(folder, "naruto") -&gt; "naruto_2"
        /// ...
        ///   </example>
        public static string GetNewFileName(StorageFolder folder, string baseFileName)
        {
            try
            {
                var names = folder.GetFilesAsync()
                                .AsTask().Result
                                .Select(f => Path.GetFileNameWithoutExtension(f.Name));

                string possibleName = baseFileName;
                int index = 1;
                while (true)
                {
                    if (names.Any(n => n.Equals(possibleName, StringComparison.CurrentCultureIgnoreCase)))
                    {
                        possibleName = baseFileName + index++;
                    }
                    else
                    {
                        break;
                    }
                }

                return possibleName;
            }
            catch (Exception)
            {
                return baseFileName;
            }
        }
开发者ID:molant,项目名称:MangApp,代码行数:44,代码来源:FileSystemUtilities.cs


示例19: AddFolder

 public async void AddFolder(StorageFolder folder)
 {
     var path = folder.Path;
     if (!_playlist.Folders.Contains(path))
         _playlist.Folders.Add(path);
     await Save();
 }
开发者ID:sunnycase,项目名称:TomatoMusic,代码行数:7,代码来源:PlaylistFile.cs


示例20: LoadData

		private async Task LoadData()
		{
			DarkMode = StorageHelper.GetSetting("DarkMode") == "1";
			DirectExit = StorageHelper.GetSetting("DirectExit") == "1";
			Tail = StorageHelper.GetSetting("Tail");
			if (string.IsNullOrEmpty(Tail))
				Tail = "From 花瓣UWP";

			var savePath = StorageHelper.GetSetting("SavePath");
			if (!string.IsNullOrWhiteSpace(savePath))
			{
				try
				{
					SavePath = await StorageFolder.GetFolderFromPathAsync(savePath);
				}
				catch (Exception ex)
				{
					SavePath = await KnownFolders.PicturesLibrary.CreateFolderAsync("huaban", CreationCollisionOption.OpenIfExists);
				}
			}
			else
			{
				SavePath = await KnownFolders.PicturesLibrary.CreateFolderAsync("huaban", CreationCollisionOption.OpenIfExists);
			}
		}
开发者ID:dblleaf,项目名称:Huaban,代码行数:25,代码来源:Setting.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Pickers.FileOpenPicker类代码示例发布时间:2022-05-26
下一篇:
C# Storage.StorageFile类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap