本文整理汇总了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);
}
示例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();
}
}
}
示例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);
}
示例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;
}
示例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();
}
}
}
}
}
}
}
}
示例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;
}
示例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);
}
示例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();
}
示例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();
}
示例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);
}
}
}
示例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();
}
}
示例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);
}
}
示例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;
}
示例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();
}
示例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;
}