Posts

Showing posts from January, 2010

C# create read write XML file

Sample file <? xml version="1.0" encoding="utf-8" ?> < root > < property name = "One" > One </ property > < values > < value name = "Two" > Two </ value > < value name = "Three" > Three </ value > </ values > </ root > Creating/Writing XML file public void 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.WriteAttributeSt

C# How to bind DataTable columns to DataGridView manually

Image
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 false dataGridView1.AutoGenerateColumns = false ; dataGridView1.DataSource = dt;

C# Regex groups

public void TestRegex() { //sample version regex string regexExpression = @" ^(?<Major>\d+)\.(?<Minor>\d+)\.(?<Build>\d+)\.(?<Revision>\d+)$ "; string text = " 1.0.0.0 "; 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 stuff gridView.ResumeLayout()

Windows user group permissions

net user <username> / domain

SQL Server get Date part from DateTime

SELECT DATEADD(dd,0, DATEDIFF(dd,0,GETDATE()))

Regular Expressions Cheatsheet, Regex

Image

Excel FaceID Viewer AddIn

http://www.dailydoseofexcel.com/archives/2004/11/23/faceid-viewer-addin/

C# Visual Studio Add-in Example

Image
Create new VS Project (Other Project Types/Extensibility/Visual Studio Add-in) If you get this error when building Add 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 subfolder MKDIR "$(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 property public partial class SampleUserControl : UserControl { public DTE2 DTE { get; set; } Update Connect.OnConnection method to open UserControl if (connectMode == ext_ConnectMode.ext_cm_A