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


C# StorageFolder.CreateFileAsync方法代码示例

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


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

示例1: saveAppendTextFile

 public async Task saveAppendTextFile(StorageFolder folder, string data, string key = null)
 {
     StorageFile myFile;
     if (key == null)
     {
         myFile = await folder.CreateFileAsync("myData.txt", CreationCollisionOption.OpenIfExists);
     }
     else
     {
         myFile = await folder.CreateFileAsync(key + ".txt", CreationCollisionOption.OpenIfExists);
     }
     await FileIO.AppendTextAsync(myFile, data);
     await FileIO.AppendTextAsync(myFile, Environment.NewLine);
 }
开发者ID:huang-lu,项目名称:Universal-App-MVVM,代码行数:14,代码来源:StorageService.cs

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

示例3: CacheUserPreference

        private const string filename = "UserPreference.txt"; //TODO: Move to constant file

        /// <summary>
        /// This checkes for strResponse - if not null, will try to write
        /// </summary>
        /// <param name="strResponse"></param>
        public async void CacheUserPreference(string strResponse)
        {
            roamingFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
            StorageFile file = await roamingFolder.CreateFileAsync(filename,CreationCollisionOption.OpenIfExists);
            if (strResponse != null)
                await FileIO.AppendTextAsync(file, strResponse);
        }
开发者ID:hasans30,项目名称:TransInfo,代码行数:13,代码来源:TransLinkService.cs

示例4: itializeClass

        public async Task itializeClass()
        {
            QueueCycleMilliSeconds = 500;
            this.folder = Windows.Storage.ApplicationData.Current.LocalFolder;

            try
            {

                this.file = folder.CreateFileAsync("SparkQueueDB.txt", CreationCollisionOption.OpenIfExists).AsTask().Result;

            }
            catch (Exception ex)
            {
                this.Errors.Add("Queue Failed To Initialize");
                this.Errors.Add(ex.Message.ToString());

            }

            inboundQueue = new Queue();
            outboundQueue = new Queue();

            //if (Program.strPowerOuttageMissedDownEvent.Length > 1)
            //{
            //    this.Enqueue(Program.strPowerOuttageMissedDownEvent);
            //    Program.strPowerOuttageMissedDownEvent = "";
            //}

            InboundDataTimer = new Timer(new TimerCallback(ProcessInboundEvent), new Object(), 250, 250);
            OutboundDataTimer = new Timer(new TimerCallback(ProcessOutboundEvent), new Object(), 250, 250);

            this.file = null;
            this.folder = null;
        }
开发者ID:bgreer5050,项目名称:SparkIoT_10586,代码行数:33,代码来源:SparkQueue.cs

示例5: UnZipFile

        async public static Task UnZipFile(StorageFile file, StorageFolder extractFolder = null)
        {
            using (var zipStream = await file.OpenStreamForReadAsync())
            {
                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.Name, CreationCollisionOption.ReplaceExisting);
                                    using (Stream outputFileStream = await outputFile.OpenStreamForWriteAsync())
                                    {
                                        await fileData.CopyToAsync(outputFileStream);
                                        await outputFileStream.FlushAsync();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
开发者ID:emptyflash,项目名称:ComicViewer,代码行数:29,代码来源:FolderZip.cs

示例6: SetFile

 public static async Task<StorageFile> SetFile(StorageFolder folder, string fileName)
 {
     StorageFile file = null;
     if (!(await DoesFileExistAsync(file, folder, fileName)))
     {
         file = await folder.CreateFileAsync(fileName);
     }
     return file;
 }
开发者ID:yjlintw,项目名称:YJToolkit,代码行数:9,代码来源:FileIO.cs

示例7: WriteNewLogAsync

        public static async Task WriteNewLogAsync(StorageFile file, StorageFolder folder, string fileName, string logString)
        {
            if (!(await FileUtil.DoesFileExistAsync(file, folder, fileName)))
            {
                file = await folder.CreateFileAsync(fileName);
            }

            await FileIO.AppendTextAsync(file, logString + Environment.NewLine);
        }
开发者ID:yjlintw,项目名称:YJToolkit,代码行数:9,代码来源:LogFile.cs

示例8: ZipFolder

        async public static Task ZipFolder(StorageFolder sourceFolder, StorageFolder destnFolder, string zipFileName)
        {
            StorageFile zipFile = await destnFolder.CreateFileAsync(zipFileName, CreationCollisionOption.ReplaceExisting);

            Stream zipToCreate = await zipFile.OpenStreamForWriteAsync();

            ZipArchive archive = new ZipArchive(zipToCreate, ZipArchiveMode.Update);
            await ZipFolderContents(sourceFolder, archive, sourceFolder.Path);
            archive.Dispose();
        }
开发者ID:vulcanlee,项目名称:Windows8Lab,代码行数:10,代码来源:FolderZip.cs

示例9: download

        public async void download(String url, Folder folder)
        {

            var uri = new Uri(url);
            var downloader = new BackgroundDownloader();
            StorageFile file = await folder.CreateFileAsync("100MB.zip",
                CreationCollisionOption.ReplaceExisting);
            DownloadOperation download = downloader.CreateDownload(uri, file);
            download.StartAsync();
        }
开发者ID:kisorbiswal,项目名称:accounter,代码行数:10,代码来源:Downloader.cs

示例10: SaveAsync

 public async static Task SaveAsync(this InkCanvas inkCanvas, string fileName, StorageFolder folder = null)
 {
     folder = folder ?? ApplicationData.Current.TemporaryFolder;
     var file = await folder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
     if (inkCanvas.InkPresenter.StrokeContainer.GetStrokes().Any())
     {
         using (var stream = await file.OpenAsync(FileAccessMode.ReadWrite))
         {
             await inkCanvas.InkPresenter.StrokeContainer.SaveAsync(stream);
         }
     }
 }
开发者ID:teamneusta,项目名称:Template10,代码行数:12,代码来源:InkUtils.cs

示例11: Start

 /// <summary>
 /// 要下载调用这个方法
 /// </summary>
 /// <param name="url">下载的文件网址的来源</param>
 /// <returns></returns>
 public static async Task Start(string filename,string url,DownloadType type,StorageFolder folder=null)
 {
     try
     {
         Uri uri = new Uri(Uri.EscapeUriString(url), UriKind.RelativeOrAbsolute);
         BackgroundDownloader downloader = new BackgroundDownloader();
         if (folder==null)
         {
             folder = await KnownFolders.MusicLibrary.CreateFolderAsync("kgdownload", CreationCollisionOption.OpenIfExists);
             switch (type)
             {
                 case DownloadType.song:
                     folder = await folder.CreateFolderAsync("song", CreationCollisionOption.OpenIfExists);
                     downloader.TransferGroup = BackgroundTransferGroup.CreateGroup("song");
                     break;
                 case DownloadType.mv:
                     folder = await folder.CreateFolderAsync("mv", CreationCollisionOption.OpenIfExists);
                     downloader.TransferGroup = BackgroundTransferGroup.CreateGroup("mv");
                     break;
                 case DownloadType.other:
                     folder = await folder.CreateFolderAsync("other", CreationCollisionOption.OpenIfExists);
                     downloader.TransferGroup = BackgroundTransferGroup.CreateGroup("other");
                     break;
                 default:
                     break;
             }
         }else
         {
             downloader.TransferGroup = BackgroundTransferGroup.CreateGroup("other");
         }
         //string name = uri.ToString().Substring(uri.ToString().LastIndexOf("/"), uri.ToString().Length);
         string name = filename;
         StorageFile file = await folder.CreateFileAsync(name, CreationCollisionOption.GenerateUniqueName);
         downloader.FailureToastNotification = DownloadedToast.Done(filename, DownloadedToast.DownResult.Fa);
         downloader.SuccessToastNotification = DownloadedToast.Done(filename, DownloadedToast.DownResult.Su);
         var download = downloader.CreateDownload(new Uri(url), file);
         TransferModel transfer = new TransferModel();
         transfer.DownloadOperation = download;
         transfer.Source = download.RequestedUri.ToString();
         transfer.Destination = download.ResultFile.Path;
         transfer.BytesReceived = download.Progress.BytesReceived;
         transfer.TotalBytesToReceive = download.Progress.TotalBytesToReceive;
         transfer.Progress = 0;
         transfers.Add(transfer);
         Progress<DownloadOperation> progressCallback = new Progress<DownloadOperation>(DownloadProgress);
         download.StartAsync().AsTask(cancelToken.Token, progressCallback);
     }
     catch
     {
         await new MessageDialog("链接已失效!").ShowAsync();
     }
 }
开发者ID:yszhangyh,项目名称:KuGouMusic-UWP,代码行数:57,代码来源:BackgroundDownload.cs

示例12: MergeFolders

 internal async static Task MergeFolders(StorageFolder source, StorageFolder target)
 {
     foreach (StorageFile sourceFile in await source.GetFilesAsync())
     {
         await sourceFile.CopyAndReplaceAsync(await target.CreateFileAsync(sourceFile.Name, CreationCollisionOption.OpenIfExists));
     }
     
     foreach (StorageFolder sourceDirectory in await source.GetFoldersAsync())
     {
         StorageFolder nextTargetSubDir = await target.CreateFolderAsync(sourceDirectory.Name, CreationCollisionOption.OpenIfExists);
         await MergeFolders(sourceDirectory, nextTargetSubDir);
     }
 }
开发者ID:cmcewen,项目名称:react-native-code-push,代码行数:13,代码来源:FileUtils.cs

示例13: CreateDefaultFileOfCities

 private static async Task<IEnumerable<City>> CreateDefaultFileOfCities(StorageFolder folder)
 {
     var file = await folder.CreateFileAsync(SETTING_KEY);
     var cities = new City[]
     {
             new City()
             {
                  Name="Namur",
                  Country="Belgique"
             }
     };
     await FileIO.WriteTextAsync(file, SerializeToJson(cities));
     return cities;
 }
开发者ID:Jean-foupahune,项目名称:WeatherApp,代码行数:14,代码来源:CitiesService.cs

示例14: SaveAsync

        public async static Task SaveAsync(
           Uri fileUri,
           StorageFolder folder,
           string fileName)
        {
            // Hitting System.UnauthorizedAccessException when the file already exists.
            // If they already have it, keep what is there.
            var file = await folder.CreateFileAsync(fileName, CreationCollisionOption.OpenIfExists);
            var downloader = new BackgroundDownloader();
            var download = downloader.CreateDownload(
                fileUri,
                file);

            await download.StartAsync();
        }
开发者ID:kusl,项目名称:vlcwinrt,代码行数:15,代码来源:DownloadAndSaveHelper.cs

示例15: SaveAsync

        private async static Task<StorageFile> SaveAsync(
              Uri fileUri,
              StorageFolder folder,
              string fileName)
        {
            var file = await folder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
            var downloader = new BackgroundDownloader();
            var download = downloader.CreateDownload(
                fileUri,
                file);

            var res = await download.StartAsync();

            return file;
        }
开发者ID:Cherlie,项目名称:ZhiHu-App-for-WP8.1,代码行数:15,代码来源:DownloadImage.cs


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