[Windows Phone 8 Apps and Games] Brandon222:
I am trying to create a Windows Phone app which allows me to create a text file and save it to the documents folder than after append to that same file after. I only need to create one file. How can I accomplish this? I have already gotten to the point where I can save to the documents folder but than after I cant append to that file only replace it. This is what I have:

using SDKTemplate;

using System;

using System.Collections.Generic;

using Windows.ApplicationModel.Activation;

using Windows.Storage;

using Windows.Storage.Pickers;

using Windows.Storage.Provider;

using Windows.UI.Xaml;

using Windows.UI.Xaml.Controls;

using Windows.UI.Xaml.Navigation;

namespace FilePicker

{

/// <summary>

/// Implement IFileSavePickerContinuable interface, in order that Continuation Manager can automatically

/// trigger the method to process returned file.

/// </summary>

public sealed partial class Scenario4 : Page, IFileSavePickerContinuable

{

MainPage rootPage = MainPage.Current;

public Scenario4()

{

this.InitializeComponent();

SaveFileButton.Click += new RoutedEventHandler(SaveFileButton_Click);

}

private void SaveFileButton_Click(object sender, RoutedEventArgs e)

{

// Clear previous returned file name, if it exists, between iterations of this scenario

OutputTextBlock.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>() { ".csv" });

// Default file name if the user does not type one in or select a file to replace

savePicker.SuggestedFileName = "Employee Info " + AliasTxt.Text;

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)

{

string answer;

string header;

string date = DateTime.Now.ToString("M/d/yyyy");

string alias = AliasTxt.Text;

int newDoc = 0;

header = "Notes" + Environment.NewLine;

answer =NotesTxt.Text;

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

//if (newDoc == 0)

//{

await FileIO.WriteTextAsync(file, header);

newDoc = 1;

//}

await FileIO.AppendTextAsync(file, answer);

// 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)

{

OutputTextBlock.Text = "File was saved.";

}

else

{

OutputTextBlock.Text = "File couldn't be saved.";

}

}

else

{

OutputTextBlock.Text = "Operation cancelled.";

}

}

private void SaveFileButton_Click_1(object sender, RoutedEventArgs e)

{

}

}

}

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using Windows.ApplicationModel.Activation;

using Windows.UI.Xaml;

using Windows.UI.Xaml.Controls;

#if WINDOWS_PHONE_APP

/// <summary>

/// ContinuationManager is used to detect if the most recent activation was due

/// to a continuation such as the FileOpenPicker or WebAuthenticationBroker

/// </summary>

public class ContinuationManager

{

IContinuationActivatedEventArgs args = null;

bool handled = false;

Guid id = Guid.Empty;

/// <summary>

/// Sets the ContinuationArgs for this instance. Using default Frame of current Window

/// Should be called by the main activation handling code in App.xaml.cs

/// </summary>

/// <param name="args">The activation args</param>

internal void Continue(IContinuationActivatedEventArgs args)

{

Continue(args, Window.Current.Content as Frame);

}

/// <summary>

/// Sets the ContinuationArgs for this instance. Should be called by the main activation

/// handling code in App.xaml.cs

/// </summary>

/// <param name="args">The activation args</param>

/// <param name="rootFrame">The frame control that contains the current page</param>

internal void Continue(IContinuationActivatedEventArgs args, Frame rootFrame)

{

if (args == null)

throw new ArgumentNullException("args");

if (this.args != null && !handled)

throw new InvalidOperationException("Can't set args more than once");

this.args = args;

this.handled = false;

this.id = Guid.NewGuid();

if (rootFrame == null)

return;

switch (args.Kind)

{

case ActivationKind.PickFileContinuation:

var fileOpenPickerPage = rootFrame.Content as IFileOpenPickerContinuable;

if (fileOpenPickerPage != null)

{

fileOpenPickerPage.ContinueFileOpenPicker(args as FileOpenPickerContinuationEventArgs);

}

break;

case ActivationKind.PickSaveFileContinuation:

var fileSavePickerPage = rootFrame.Content as IFileSavePickerContinuable;

if (fileSavePickerPage != null)

{

fileSavePickerPage.ContinueFileSavePicker(args as FileSavePickerContinuationEventArgs);

}

break;

case ActivationKind.PickFolderContinuation:

var folderPickerPage = rootFrame.Content as IFolderPickerContinuable;

if (folderPickerPage != null)

{

folderPickerPage.ContinueFolderPicker(args as FolderPickerContinuationEventArgs);

}

break;

case ActivationKind.WebAuthenticationBrokerContinuation:

var wabPage = rootFrame.Content as IWebAuthenticationContinuable;

if (wabPage != null)

{

wabPage.ContinueWebAuthentication(args as WebAuthenticationBrokerContinuationEventArgs);

}

break;

}

}

/// <summary>

/// Marks the contination data as 'stale', meaning that it is probably no longer of

/// any use. Called when the app is suspended (to ensure future activations don't appear

/// to be for the same continuation) and whenever the continuation data is retrieved

/// (so that it isn't retrieved on subsequent navigations)

/// </summary>

internal void MarkAsStale()

{

this.handled = true;

}

/// <summary>

/// Retrieves the continuation args, if they have not already been retrieved, and

/// prevents further retrieval via this property (to avoid accidentla double-usage)

/// </summary>

public IContinuationActivatedEventArgs ContinuationArgs

{

get

{

if (handled)

return null;

MarkAsStale();

return args;

}

}

/// <summary>

/// Unique identifier for this particular continuation. Most useful for components that

/// retrieve the continuation data via <see cref="GetContinuationArgs"/> and need

/// to perform their own replay check

/// </summary>

public Guid Id { get { return id; } }

/// <summary>

/// Retrieves the continuation args, optionally retrieving them even if they have already

/// been retrieved

/// </summary>

/// <param name="includeStaleArgs">Set to true to return args even if they have previously been returned</param>

/// <returns>The continuation args, or null if there aren't any</returns>

public IContinuationActivatedEventArgs GetContinuationArgs(bool includeStaleArgs)

{

if (!includeStaleArgs && handled)

return null;

MarkAsStale();

return args;

}

}

/// <summary>

/// Implement this interface if your page invokes the file open picker

/// API.

/// </summary>

interface IFileOpenPickerContinuable

{

/// <summary>

/// This method is invoked when the file open picker returns picked

/// files

/// </summary>

/// <param name="args">Activated event args object that contains returned files from file open picker</param>

void ContinueFileOpenPicker(FileOpenPickerContinuationEventArgs args);

}

/// <summary>

/// Implement this interface if your page invokes the file save picker

/// API

/// </summary>

interface IFileSavePickerContinuable

{

/// <summary>

/// This method is invoked when the file save picker returns saved

/// files

/// </summary>

/// <param name="args">Activated event args object that contains returned file from file save picker</param>

void ContinueFileSavePicker(FileSavePickerContinuationEventArgs args);

}

/// <summary>

/// Implement this interface if your page invokes the folder picker API

/// </summary>

interface IFolderPickerContinuable

{

/// <summary>

/// This method is invoked when the folder picker returns the picked

/// folder

/// </summary>

/// <param name="args">Activated event args object that contains returned folder from folder picker</param>

void ContinueFolderPicker(FolderPickerContinuationEventArgs args);

}

/// <summary>

/// Implement this interface if your page invokes the web authentication

/// broker

/// </summary>

interface IWebAuthenticationContinuable

{

/// <summary>

/// This method is invoked when the web authentication broker returns

/// with the authentication result

/// </summary>

/// <param name="args">Activated event args object that contains returned authentication token</param>

void ContinueWebAuthentication(WebAuthenticationBrokerContinuationEventArgs args);

}

#endif