Skip to main content

Posts

Showing posts from 2017

Load Json array using jQuery and javascript

Here is the script to load json array- <head> <title> Page Title </title> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js" ></script> </head> <body> <div id= "images" > test </div> </body> var dictionary = [ { "id" : "0" , "name" : "ABC" }, { "id" : "1" , "name" : "DEF" } , { "id" : "2" , "name" : "PQR" }, { "id" : "3" , "name" : "xyz" , "name2" : "xyz2" } ]; $( function (){ for ( var ke in dictionary ) { if (dictionary.hasOwnProperty(ke)) { var id = dictionary [ke].id; var name = dictionary [ke].name; //create a anchor element using id. //when

Convert class object to XML using C# in .NET

People is the class whose object needs to be converted in XML string which later can be stored in a DB field or as XML file. public class PersonDetail { public string FirstName { get ; set ; } public string LastName { get ; set ; } } public class People { public People () { PeopleList = new List<ProductImage>(); } public List<PersonDetail> PeopleList{ get ; set ; } } Function to convert class object to XML string: public static string SerializeToXml<T>(T value ) { StringWriter writer = new StringWriter(CultureInfo.InvariantCulture); XmlSerializer serializer = new XmlSerializer( typeof (T)); serializer.Serialize(writer, value ); return writer.ToString(); } C# code to convert class object to XML string: People peopleDetailList = new People(); PersonDetail pDetail = new PersonDetail ();

Enable, Disable and Start the task of task scheduler in C#.Net

Below function demonstrates how to enable, disable and run the already created scheduled task. It will first check if the task exists in task scheduler: public static void updateUserTaskInScheduler ( string action) { try { ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = "cmd.exe" ; startInfo.Arguments = "/C schtasks /query /TN <<TaskNameWithQuotes>>; //Check if task exists startInfo.RedirectStandardOutput = true ; startInfo.UseShellExecute = false ; startInfo.CreateNoWindow = true ; startInfo.WindowStyle = ProcessWindowStyle.Hidden; if (System.Environment.OSVersion.Version.Major < 6 ) { startInfo.Verb = "runas" ; } using (Process process = Process.Start(startInfo)) {

Text styling of HTML5 Canvas using fabricjs

In previous post I have shared code to add text to HTML5 canvas using fabricjs. refer http://newapputil.blogspot.in/2017/03/write-text-on-html5-canvas-using.html Here in this post below is the code to change text style to italic , making text bold and underline the text using fabricjs on html5 canvas. This code will work when text object is selected. <canvas id= "c" width= "600" height= "600" ></canvas> <input type= "text" class= "add-text" > <button class= "add-text-btn" > Add Text </button> <button class= "bold-text-btn" > Bold </button> <button class= "underline-text-btn" > Underline </button> <button class= "italic-text-btn" > Italic </button> javascript code: // initialize fabric canvas and assign to global windows object for debug var canvas = window ._canvas = new fabric.Canvas( 'c

Drawing a dotted circle using C#.NET windows form

Dotted circle can be used for showing circular progress. Here is the code to draw a dotted/dashed circle using C# in windows form application: using System ; using System.Collections.Generic ; using System.ComponentModel ; using System.Data ; using System.Drawing ; using System.Linq ; using System.Text ; using System.Windows.Forms ; using System.Drawing.Drawing2D ; using System.Threading ; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1 () { InitializeComponent(); } int angle = 0 ; int Startangle = 0 ; private void Form1_Load ( object sender, EventArgs e) { } private void panel1_Paint ( object sender, PaintEventArgs e) { //draw a dashed cricle using(Graphics g = panel1.CreateGraphics()) { System.Drawing.Rectangle rectangle = new System.Drawi

Write text on HTML5 Canvas using fabricjs

Here is the code to add text on html5 canvas using fabricjs <canvas id= "c" width= "600" height= "600" ></canvas> <input type= "text" class= "add-text" > <button class= "add-text-btn" > Add Text </button> Javascript code: var canvas = window ._canvas = new fabric.Canvas( 'c' ); fabric.Image.fromURL( 'http://fabricjs.com/assets/printio.png' , function (img){ canvas.add(img.scale( 1 ).set({ left : 0 , top : 0 , angle : 0 , selectable : false })); }); canvas.renderAll(); document .querySelectorAll( '.add-text-btn' )[ 0 ].addEventListener( 'click' , function (){ var textToAdd = new fabric.Text( document .querySelectorAll( '.add-text' )[ 0 ].value, { fontFamily : 'arial' }); canvas.add(textToAdd); }); Link for jsfiddle https://jsfiddle.net/nvivekgoyal/ybogocmf/

Convert content of XML file to JSON string in C#.Net

Convert content of XML file to JSON string in C#.Net The below function will convert the content of XML file to JSON string: private string convertXMLToJSON () { string xmlLogPath = "<<Path to the xml file>>" ; // Load the XML file var xDocument = System.Xml.Linq.XDocument.Load(xmlLogPath); // Read the XML file content and write it to string string xml = xDocument.ToString(); // Load the XML string XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); // Convert the XML string to JSON string string jsonText = JsonConvert.SerializeXmlNode(doc); //Release the memory doc = null ; xmlLogPath = null ; xml = null ; xDocument = null ; //Return the JSON string return jsonText; } IMPORTANT NOTE: Releasing object memory is