Skip to content

Instantly share code, notes, and snippets.

View Microsofttechies's full-sized avatar

Venkat G Microsofttechies

View GitHub Profile
@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: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: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: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:df7f045c8e2a8fe1874d
Last active August 29, 2015 14:19
XML to string Self-closing element does not fire a EndElement event
XmlTextReader objreader = new XmlTextReader("c:\\a.xml");
StringBuilder strBuilXML = new StringBuilder();
while (objreader.Read())
{
if (objreader.IsStartElement())
{
if (objreader.IsEmptyElement)
{
@Microsofttechies
Microsofttechies / gist:e1dfeb99049a938ecb66
Created April 16, 2015 17:21
powershell script to run exe
cls
$startTime = Get-Date
Write-Host "Start " + $startTime.ToString("u")
$exePath = "C:\My.exe"
& $exePath
$endTime = Get-Date
Write-Host "End " + $endTime.ToString("u")
@Set exePath="C:\My.exe"
Echo "Call PS1"
PowerShell.exe Set-ExecutionPolicy RemoteSigned; "C:\MyScript.PS1" -exePath %exePath%
Echo "End PS1"
PAUSE
@Microsofttechies
Microsofttechies / gist:0b5d8edb19b5a560fe0f
Created April 16, 2015 17:45
Calling exe from Powershell
Param
(
[string]$exePath = $null
)
write-host “Calling exe”
$startTime = Get-Date
Write-Host "Start time " + $startTime.ToString("u")
$exePath = $exePath
& $exePath
@Microsofttechies
Microsofttechies / gist:e2214563c4a4c91cdf82
Created May 8, 2015 00:12
C# Append lines to a file using a StreamWriter
StringBuilder strBuilLog = new StringBuilder();
string strLogData = "Welcome to log data \t";
strBuilLog.Append(strLogData);
string strLogData2 = "Welcome to log data 2" + Environment.NewLine;
strBuilLog.Append(strLogData2);
string strLogDataFinal = "Welcome to log data final \t";
strBuilLog.Append(strLogDataFinal);
using (StreamWriter strwLog = new StreamWriter("c:\\log.txt"))
{
@Microsofttechies
Microsofttechies / gist:5f40662980981b8d122d
Last active August 29, 2015 14:20
c# xelement change attribute value
<Root>
<Address myatt="abc">NY</Address>
<Address>AUS</Address>
</Root>
if (myXelement.Element("Address").Attribute("myatt").Value == "Abc")
{
myXelement.Element("Address").Attribute("myatt").Value = "XYZ";
}