コード例 #1
0
        private async void btnSave_Click(object sender, RoutedEventArgs e)
        {
            var savePicker = new FileSavePicker();

            savePicker.FileTypeChoices.Add("Arduino Code File", new List <string>()
            {
                ".ino"
            });
            savePicker.SuggestedFileName = "CodeByProjectPhoenix";
            var file = await savePicker.PickSaveFileAsync();

            if (file != null)
            {
                var         c      = txbCCode.Text.ToArray();
                List <byte> buffer = new List <byte>();
                for (int i = 0; i < c.Length; i++)
                {
                    buffer.Add(Convert.ToByte(c[i]));
                }
                CachedFileManager.DeferUpdates(file);
                await FileIO.WriteBytesAsync(file, buffer.ToArray());

                Windows.Storage.Provider.FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(file);

                MessageDialog md = new MessageDialog(status.ToString());
                await md.ShowAsync();
            }
        }
コード例 #2
0
        private async Task SaveCalendarInk()
        {
            Windows.Storage.StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;

            try
            {
                var file = await localFolder.CreateFileAsync(_CalendarMonth.Month.ToString("yyyy-MM") + ".gif", Windows.Storage.CreationCollisionOption.ReplaceExisting);

                Windows.Storage.CachedFileManager.DeferUpdates(file);
                using (IRandomAccessStream stream = await file.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite))
                {
                    using (IOutputStream outputStream = stream.GetOutputStreamAt(0))
                    {
                        await calendarCanvas.InkPresenter.StrokeContainer.SaveAsync(outputStream);

                        await outputStream.FlushAsync();
                    }
                }

                // Finalize write so other apps can update file.
                Windows.Storage.Provider.FileUpdateStatus status = await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(file);

                if (status == Windows.Storage.Provider.FileUpdateStatus.Complete)
                {
                    Debugger.WriteDebugLog("Calendar ink saved.");
                }
                else
                {
                    throw new Exception("Calendar ink couldn't be saved. Status=" + status.ToString() + ".");
                }
            }
            catch (Exception ex)
            {
                Debugger.WriteErrorLog("Error occured while saving calendar canvas.", ex);
                await new MessageDialog(ex.Message, "Error occured while saving calendar canvas.").ShowAsync();
            }
        }