Answered by:
Opening & editing a txt file

Question
-
Hello everybody,
i'm new to Windows 8 and WinJS and i have a question. How can i open a .txt file and write new content( with the old content) in this .txt file?
It would be awesome if somebody can help me :)
Sincerly, saiikon
Sunday, November 11, 2012 9:52 PM
Answers
-
Hi,
Please refer to the code as follow:
localFolder.getFileAsync("myfile.data") .then(function (file) { Windows.Storage.FileIO.writeTextAsync(file, "I am rewrite again again").done(function () { localFolder.getFileAsync("myfile.data") .then(function (file) { return Windows.Storage.FileIO.readTextAsync(file); }).done(function (text) { // activitiesArray = JSON.parse(text); document.getElementById("content").innerHTML = text; }); }); });
More details, please refer to: http://msdn.microsoft.com/en-us/library/windows/apps/hh701508.aspx .
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
Tuesday, November 13, 2012 2:03 AM
All replies
-
Hi,
Please refer the example as follow:
//var jsonText = JSON.stringify(activitiesArray) var jsonText="hey, I am transfered"; var localFolder = Windows.Storage.ApplicationData.current.localFolder; //localFolder.createFileAsync("myfile.data", Windows.Storage.CreationCollisionOption.replaceExisting) // .then(function (file) { // return Windows.Storage.FileIO.writeTextAsync(file, jsonText); // }); localFolder.getFileAsync("myfile.data") .then(function (file) { return Windows.Storage.FileIO.readTextAsync(file); }).done(function (text) { // activitiesArray = JSON.parse(text); document.getElementById("content").innerHTML=text; });
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code FrameworkMonday, November 12, 2012 9:05 AM -
Hey man!
Thansk for the answer, i have tried this code now and it does nothing :/ No error or something else..
function writeFile(input) { var applicationData = Windows.Storage.ApplicationData.current; var localFolder = applicationData.localFolder; localFolder.getFileAsync("last.txt") .then(function (sampleFile) { var old = Windows.Storage.FileIO.readTextAsync(sampleFile); return Windows.Storage.FileIO.writeTextAsync(sampleFile, old + input); }); }
Monday, November 12, 2012 1:24 PM -
Hi,
Please refer to the code as follow:
localFolder.getFileAsync("myfile.data") .then(function (file) { Windows.Storage.FileIO.writeTextAsync(file, "I am rewrite again again").done(function () { localFolder.getFileAsync("myfile.data") .then(function (file) { return Windows.Storage.FileIO.readTextAsync(file); }).done(function (text) { // activitiesArray = JSON.parse(text); document.getElementById("content").innerHTML = text; }); }); });
More details, please refer to: http://msdn.microsoft.com/en-us/library/windows/apps/hh701508.aspx .
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
Tuesday, November 13, 2012 2:03 AM