1

c# を使用して Windows Phone 8.1 アプリを作成する方法を学習しようとしています。アプリで位置データを取得し、GPX ファイルを作成して、そのデータをウェイポイントに書き込みます。場所を取得し、必要な xml を記述し、FileSavePicker を使用して新しいファイルを作成できます。問題は、FileSavePicker が空のファイルを作成するだけで、ContinueFileSavePicker 部分に書き込まれたすべてのものが機能しないことです。私が欠けているものを誰かが知っていますか?ありがとう

public sealed partial class MainPage : Page
{
    public MainPage()
    {
        this.InitializeComponent();

        this.NavigationCacheMode = NavigationCacheMode.Required;
    }

    /// <summary>
    /// Invoked when this page is about to be displayed in a Frame.
    /// </summary>
    /// <param name="e">Event data that describes how this page was reached.
    /// This parameter is typically used to configure the page.</param>
    protected async override void OnNavigatedTo(NavigationEventArgs e)
    {
        //await getLocation();

    }

    private async void Location_Click(object sender, RoutedEventArgs e)
    {

        await getLocation();

    }

    private  void Save_Click(object sender, RoutedEventArgs e)
    {
        // Clear previous returned file name, if it exists, between iterations of this scenario
        Status2.Text = "";

        FileSavePicker savePicker = new FileSavePicker();
        savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
        // Dropdown of file types the user can save the file as
        savePicker.FileTypeChoices.Add("Plain Text", new List<string>() { ".txt" });
        // Default file name if the user does not type one in or select a file to replace
        savePicker.SuggestedFileName = "New Document";

        savePicker.PickSaveFileAndContinue();
    }

     //<summary>
     //Handle the returned file from file picker
     //This method is triggered by ContinuationManager based on ActivationKind
     //</summary>
     //<param name="args">File save picker continuation activation argment. It cantains the file user selected with file save picker </param>


    public async void ContinueFileSavePicker(FileSavePickerContinuationEventArgs args)
    {
        StorageFile file = args.File;
        if (file != null)
        {
            // Prevent updates to the remote version of the file until we finish making changes and call CompleteUpdatesAsync.
            CachedFileManager.DeferUpdates(file);
            // write to file
            await FileIO.WriteTextAsync(file, file.Name);
            // Let Windows know that we're finished changing the file so the other app can update the remote version of the file.
            // Completing updates may require Windows to ask for user input.
            FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(file);
            if (status == FileUpdateStatus.Complete)
            {
                Status2.Text = "File " + file.Name + " was saved.";
            }
            else
            {
                Status2.Text = "File " + file.Name + " couldn't be saved.";
            }
        }
        else
        {
            Status2.Text = "Operation cancelled.";
        }
    }
4

1 に答える 1

0

答えはここにあります

読む:

テキスト ファイルの書き込み これらのメソッドを使用して、ローカル フォルダーに新しいテキスト ファイルを書き込みます。

  • メソッド StorageFolder.CreateFileAsync を使用して新しいファイルを作成します。
  • ストリームを返す StorageFile.OpenAsync メソッドを使用してファイルを開きます。
  • openAsync によって返されたストリームを介して DataWriter に対して開きます。
  • DataWriter.WriteString メソッドを使用して、テキストをストリームに書き込みます。
  • メソッドを使用して DataWriter StoreAsync をフラッシュして閉じます。

私の場合、「B」と呼ばれるバイト配列にある情報です。それで:

Await FileIO.WriteBytesAsync (File, B)

于 2015-07-25T03:25:24.860 に答える