Skip to content

Instantly share code, notes, and snippets.

View Microsofttechies's full-sized avatar

Venkat G Microsofttechies

View GitHub Profile
@Microsofttechies
Microsofttechies / gist:ccf5f9c4b5db5d4a3f11
Created April 14, 2015 07:55
Read special characters back from XmlDocument in c#
To Get escapded values
public string EscapeXMLValue(string value)
{
if (string.IsNullOrEmpty(s)) return s;
string temp = s;
temp = temp.Replace("'","&apos;").Replace( "\"", "&quot;").Replace(">","&gt;").Replace( "<","&lt;").Replace( "&","&amp;");
return temp ;
}
@Microsofttechies
Microsofttechies / gist:58d8e27c642fa61f0a78
Created April 9, 2015 00:50
c# linq sequence contains no elements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Test.linq
{
public partial class WebForm1 : System.Web.UI.Page
@Microsofttechies
Microsofttechies / gist:885ebcef55b9896c7bae
Last active August 29, 2015 14:18
Aras create new item using AML with revision
<AML>
<Item type='Part' action='add'>
<item_number>P0011</item_number>
<title>My Part1</title>
<name>P0011</name>
<major_rev>B</major_rev>
<description>Welcome new part1</description>
</Item>
</AML>
@Microsofttechies
Microsofttechies / gist:6958fa2f5f62bb4b1eb6
Last active June 15, 2022 12:58
c# dictionary add if not exist
if (variables == null)
{
variables = new Dictionary<string, object>();
}
if(variables.ContainsKey(name))
{
variables[name] = value;
}
else
{
@Microsofttechies
Microsofttechies / gist:1a48cd313775967253b8
Created April 6, 2015 04:52
dataSet.GetXml() doesn't return xml for null or blank columns
First clone the DataTable, make all columns of type string, replace all null values with string.empty, then call GetXml on a new DataSet.
//First bind XML data in to data set..objDataSet
DataTable dt = objDataSet.Tables[0];
DataTable dtCloned = dt.Clone();
foreach (DataColumn dc in dtCloned.Columns)
@Microsofttechies
Microsofttechies / gist:15211be08573e256c47a
Last active August 29, 2015 14:18
{"<RootElementName xmlns=''> was not expected.} XML Deserialize in C#
XmlRootAttribute xRoot = new XmlRootAttribute();
xRoot.ElementName = "RootElementName";
xRoot.IsNullable = true;
XmlSerializer objSer = new XmlSerializer(typeof(Result), xRoot);
FileStream objF = new FileStream("C:\\a.xml", FileMode.Open);
Result varResult = (Result)serializer.Deserialize(objF);
@Microsofttechies
Microsofttechies / gist:37b2dd3103f98fc3f490
Created April 3, 2015 17:13
C# XML read and remove namespace
XmlDocument xmlD = new XmlDocument();
xmlD.Load("C:\\a.xml");
string strxml = xmlD.OuterXml.ToString();
Regex regEx = new Regex(@"< \?xml.*?\?>");
strxml = regEx.Replace(strxml, " ");
@Microsofttechies
Microsofttechies / gist:3b66b6e0007f3bf75ca8
Created April 2, 2015 23:42
c# convert excel to xml
OleDbConnection objConnection;
DataSet objDs;
OleDbDataAdapter objCommand;
string strExcelPath = "C:\\MyExcel.xlsm";
if (Path.GetExtension(strExcelPath) == ".xls")
{
objConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strExcelPath + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"");
@Microsofttechies
Microsofttechies / gist:3286110b0c0989a1f918
Last active August 29, 2015 14:18
C# read excel OleDbConnection connection for .xls and .xlsx
using System.Threading.Tasks;
using System.Data.OleDb;
using System.Data;
using System.IO;
//Code
OleDbConnection oledbConn;
string path = "C:\\MyExcel.xlsx";
@Microsofttechies
Microsofttechies / gist:078431e6e56ae6d92d72
Created March 29, 2015 18:57
Aras Innovator Item applyAML(string AML)
Innovator inn = this.getInnovator();
string AML = "<AML><Item type='Customer' action='get'/></AML>";
Item result = inn.applyAML(AML);