Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

C# Convert DataTable to Json File using Newtonsoft.Json DLL

 // Install Newtonsoft.Json from nuget
//then add namespace
//Using NewtonSoft.Json;

public bool Write(string filePath, DataTable table, string fileName)
        {
            try
            {
                bool success = false;
                using (var file = File.CreateText(filePath + "" + fileName))
                {
                    JsonSerializer serializer = new JsonSerializer();
                    serializer.Serialize(file, table);
                    success = true;
                }
                return success;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Comment

C# Convert Json File to DataTable using Newtonsoft.Json DLL

// Install Newtonsoft.Json from nuget 
// Use the namespace after
//Using Newtonsoft.Json;
public DataTable Read(string filePath)
        {
            try
            {
                //check if json structure is okay (http://jsonlint.com)
                //generate object class http://www.jsonutils.com

                DataTable dt = new DataTable();
                dt = JsonConvert.DeserializeObject<DataTable>(File.ReadAllText(filePath));

                return dt;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Comment

PREVIOUS NEXT
Code Example
Javascript :: area of a triangle javascript 
Javascript :: ajax is not a function 
Javascript :: v-for only getting one first value vuejs 
Javascript :: convert array object to string javascript 
Javascript :: react context api with hooks 
Javascript :: outer click on div hide div in jqeury 
Javascript :: how to apply border to table in angular 
Javascript :: angular right click action 
Javascript :: index of 
Javascript :: convert milliseconds to time javascript 
Javascript :: tolocale string no seconds 
Javascript :: Javascript make alert box 
Javascript :: react native data map is not a function 
Javascript :: javascript check for duplicates in array 
Javascript :: useref in functional component 
Javascript :: faker.js 
Javascript :: angular build deploy url 
Javascript :: email regex javascript 
Javascript :: datatable set row id 
Javascript :: create-react-app npm yarn 
Javascript :: global axios vue 2 
Javascript :: axios all methods 
Javascript :: js get element by innertext 
Javascript :: react 18 rendering twice 
Javascript :: javascript list to object map 
Javascript :: javascript select from array where 
Javascript :: javascript valueOf() Method 
Javascript :: how to print a array js 
Javascript :: get role id from role position 
Javascript :: sub array javascript 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =