I’m developing a Windows 8 application using HTML5. The application requires some user data to create a new event. The event has a title, description, date and time. I want to store this data in a text file in JSON format after the user has filled the form so that it can be visible the next time user opens the application.
I can find different methods of writing JSON objects to text file but I can’t find anything related to appending data at the end of the text file. Basically, I have one events.txt from which I read and display data and I want to append events to the same .txt after user adds an event.
My events.txt looks like this
[
{
"key": "event1",
"title": "title1",
"description": "description1",
"date": "<sample date>",
"time": "<sample time>",
"backgroundImage": "../images/logo.png"
}
]
I’m reading the events from this file using the following code
WinJS.xhr({ url: "../data/events.txt" }).then(function (xhr) {
var events = JSON.parse(xhr.responseText);
events.forEach(function (feed) {
event.push({
group: feed,
key: feed.key,
title: feed.title,
description: feed.description,
date: feed.date,
time: feed.time,
backgroundImage: feed.backgroundImage
});
});
});
Any kind of help will be greatly appreciated as I’m running tight on a deadline here.
Thanks.
Are you looking for this File Access sample for
Consumer Preview?If I understood your question correctly, I think here are some important API that you want to use.
More reference to FileIO API:
http://msdn.microsoft.com/en-us/library/windows/apps/hh701440.aspx
In addition, why don’t you consider using
local storageorindexedDBto store your event info?