Showing posts from January, 2010

C# create read write XML file

Sample file<?xml version="1.0" encoding="utf-8"?><root><propertyname="One">One</property><values><valuename="Two">Two</value><valuename="Three">Three</value></values></root>Creating/Writing XML filepublicvoid TestXMLWriter() { string filePath = @"c:\temp\sample.xml"; List<string> values = new List<string>(); values.Add("Two"); values.Add("Three"); XmlWriterSettings xmlSettings = new XmlWriterSettings(); xmlSettings.Indent = true; xmlSettings.Encoding = Encoding.UTF8; using (XmlWriter writer = XmlWriter.Create( filePath, xmlSettings )) { writer.WriteStartDocument(); writer.WriteStartElement("root"); { writer.WriteStartElement("property"); writer.WriteAttributeString("name", "One"); writer.WriteString("One"); writer.Write…

C# How to bind DataTable columns to DataGridView manually

dt = new DataTable(); dt.Columns.Add("Reference", typeof (string)); dt.Columns.Add("Version", typeof(string)); dt.Columns.Add("LatestVersion", typeof(string)); //5. Set AutogenerateColumns to falsedataGridView1.AutoGenerateColumns = false; dataGridView1.DataSource = dt;

C# Regex groups

publicvoid TestRegex() { //sample version regexstring regexExpression = @"^(?<Major>\d+)\.(?<Minor>\d+)\.(?<Build>\d+)\.(?<Revision>\d+)$"; string text = ""; Regex regex = new Regex(regexExpression); //case insensitive//Regex regex = new Regex(regextTextBox.Text, RegexOptions.IgnoreCase); Match match = regex.Match(text); if (match.Success) { foreach (string groupName in regex.GetGroupNames()) { Console.WriteLine("{0}={1}", groupName, match.Groups[groupName]); } } }

C# Update GridView without redrawing, refreshing

gridView.SuspendLayout() //do some stuffgridView.ResumeLayout()

Windows user group permissions

net user <username> /domain

SQL Server get Date part from DateTime


Regular Expressions Cheatsheet, Regex


Excel FaceID Viewer AddIn

C# Visual Studio Add-in Example

Create new VS Project (Other Project Types/Extensibility/Visual Studio Add-in)If you get this error when buildingAdd this to Pre-build event command line:IF EXIST $(TargetPath).LOCKED (del $(TargetPath).LOCKED) ELSE (IF EXIST $(TargetPath) (move $(TargetPath) $(TargetPath).LOCKED))Update Add-in location in SampleAddin.AddIn<Assembly>SampleAddin/SampleAddin.dll</Assembly>Add this to Post-build event command line to copy your Addin to subfolderMKDIR "$(ProjectDir)bin\SampleAddin"
XCOPY "$(ProjectDir)bin\SampleAddin.dll" "$(ProjectDir)bin\SampleAddin" /Y /R
DEL "$(ProjectDir)bin\SampleAddin.dll"
DEL "$(ProjectDir)bin\SampleAddin.pdb" Create New UserControl add add DTE2 propertypublicpartialclass SampleUserControl : UserControl
public DTE2 DTE { get; set; } Update Connect.OnConnection method to open UserControlif (connectMode == ext_ConnectMode.ext_cm_AfterStartup
|| connectMode == ext_ConnectMode.ext_cm_St…