Ratna Raju Ratna Raju - 11 months ago 80
AngularJS Question

How to store and update JSON data into file using ASP.NET MVC?

I want to store and update POST json data into a file using ASP.NET MVC. I'm sending data:

url: "AddMenus",
dataType: 'json',
method: 'POST',
data: MenusInfo,
headers: {
"Content-Type": "application/json"

Add Menus is action method and MenusInfo is a JSON object.

Answer Source

Assuming no other requirements other than to read the JSON from the request and update the JSON contained in that file as requested in the question:

public ActionResult AddMenus()
    // Get the raw json
    Request.InputStream.Seek(0, SeekOrigin.Begin);
    string jsonData = new StreamReader(Request.InputStream).ReadToEnd();

    // Creates or overwrites the file with the contents of the JSON
    System.IO.File.WriteAllText(@"C:\textfile.txt", jsonData);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download