user3859163
user3859163

Reputation: 43

how to use streamwriter and file append in Windows phone8.1?

In windows phone 8.1 i want to use streamwriter in text, and appending text to file end. But the text is appended to the beginning of the file. how to appending text to file end?

StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(@"ms-appx:///input_category_list.txt"));
using (StreamWriter sWrite = new StreamWriter(await file.OpenStreamForWriteAsync(), System.Text.UTF8Encoding.UTF8))
{  
    sWrite.WriteLine(write_category_box.Text);
    await sWrite.FlushAsync();                        
}

Upvotes: 1

Views: 1252

Answers (2)

w.b
w.b

Reputation: 11238

There's no need for StreamWriter in Windows Runtime, you can use FileIO class (which is easier):

StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(@"ms-appx:///input_category_list.txt"));

await FileIO.AppendTextAsync(file, write_category_box.Text, UnicodeEncoding.Utf8);

Upvotes: 4

bumbumpaw
bumbumpaw

Reputation: 2528

change your code to this:

new StreamWriter(await file.OpenStreamForWriteAsync(),System.Text.UTF8Encoding.UTF8,true))

if you overrride StreamWriter constructor, as true, this will set to append text. Otherwise overwrite it.

Upvotes: 0

Related Questions