Can I update the database with JSON files that exist in a particular folder? RRS feed

  • Question

  • User-1404740798 posted

    Can I implement MVC so that multiple JSON files can be replaced by specifying a specific folder

    and the JSON file can be automatically uploaded to the database?

    Monday, July 1, 2019 5:50 AM

All replies

  • User753101303 posted


    Some more context could help. Are you trying to allow a user to select directories for an upload? See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input/file and scroll down to "non standard attributes".

    Also it's unclear if those files are used to update data in the database or if the content should be stored directly in the db (it's basically an unrelated topic).

    Monday, July 1, 2019 9:05 AM
  • User-474980206 posted
    If you mean can the client just select a folder and upload all files in the folder, then no, this can not be done with a html browser application. You would need to write a browser plugin, or a native client application.

    You can use multiple select in the input file control, and the user can select all files in the folder with one pick, you don’t need an input file controller per file.
    Monday, July 1, 2019 2:10 PM
  • User1520731567 posted

    Hi slkim,

    Can I update the database with JSON files that exist in a particular folder?

    I think you could.

    Firstly,the data structure of the json file is consistent with the database table, which is convenient for CURD.

    And then read data from your json files and convert data to model type,finally CRUD by EF.

    For example:

         public class TestModel
                public int Id { get; set; }
                public string Name { get; set; }

    json file:

    //you will get data in a TestModel type from json file in specific folder
    TestModel model = JsonConvert.DeserializeObject<TestModel>(System.IO.File.ReadAllText(@"D:\model.json"));

    then CRUD by EF:

    db.YourTables.Add(model);//add data from json file

    More details about Newtonsoft, you could refer to:


    Best Regards.

    Yuki Tao

    Tuesday, July 2, 2019 3:04 AM