Thursday, February 9, 2017

The ' ' character, hexadecimal value 0x20, cannot be included in a name.


I want to convert Json file to xml file. Many code available on internet you can applied easily and It is working fine. but sometime we got an error. 

"The ' ' character, hexadecimal value 0x20, cannot be included in a name."


Sol 1- jsonStr.Replace(“ “,””);
With this solution, String does not contain any space.

Sol 2-
var objJson = JArray.Parse(jsonString);
 foreach (var fix in (from property in objJson.Descendants().OfType<JProperty>()
         let newName = XmlConvert.EncodeLocalName(property.Name.Replace(" """))
         where newName != property.Name
               select new { Old = property, New = new JProperty(newName, property.Value) })          .ToList())

                XmlDocument xdoc = JsonConvert.DeserializeXmlNode("{\"root\":" + objJson.ToString() + "}""root");

Thursday, June 9, 2016

Alternate Row Color in Repeater in

In this article I will explain how to change alternate row color of Repeater on aspx page. There is no need to manage your own variable. this has the benefit of being completely based in your UI code.

 Code:   just paste my code in ItemTemplate and it should work.

<%# Container.ItemIndex % 2 == 0 ? "<div>" : "<div style='background-color: #000; padding:2px'>" %>

Wednesday, February 17, 2016

How to compare two datatable using Linq in

Compare two datatable having same datatype column using LINQ Query.
This article is used to get different records from datatable1 compared with datatable2 using LINQ Query.  This mismatched record get from another datatable. 


var record1 = datatable1.AsEnumerable().Select(a => new {              
                  matchColumnValue = a["columnName"].ToString() });

var record2 = datatable2.AsEnumerable().Select(b => new {
                   matchColumnValue = b["columnName"].ToString() });

var exceptTotalRecord = record1.Except(record2);

DataTable datatableFinal = (from a in exceptDirectFare.AsEnumerable()
  select a).CopyToDataTable();