-
Archives
- May 2010
- April 2010
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009
- August 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- December 2007
- July 2007
- June 2007
- October 2006
- September 2006
- August 2006
- July 2006
- June 2006
- May 2006
- April 2006
- March 2006
- February 2006
- January 2006
- November 2005
- October 2005
- September 2005
- August 2005
- July 2005
- June 2005
- May 2005
- April 2005
- March 2005
- February 2005
- January 2005
- December 2004
- October 2004
- August 2004
- July 2004
- June 2004
- December 1969
-
Meta
Category Archives: C# Snippets
Split a Camel-Cased word into its components
I needed to split a camel-cased word into it’s component parts, and found the following extension method to help out. It works pretty well. public static string SplitCamelCase( this string str ) { return Regex.Replace( Regex.Replace( str, @"(\P{Ll})(\P{Ll}\p{Ll})", "$1 $2" … Continue reading
Posted in .NET, C# Snippets, Extension Methods, Uncategorized
Leave a comment
Apostrophe In RowFilter
According to ASP.NET Resources, there is a problem when using apostrophes in a RowFilter expression in a DataView. The fix seems to be to double the apostrophes (“O”Mally”) rather than escaping them (“O\’Mally”)
Posted in C# Snippets
Comments Off
Iterate through enum values
A quick example of how to iterate through the values in an enum… enum myEnum { one, two, three, four, five, }; foreach (int i in Enum.GetValues(typeof(myEnum ))) { myEnum myItem = (myEnum )Enum.ToObject(typeof(myEnum ), i); System.Diagnostics.Debug.WriteLine(myItem.ToString()); }
Posted in .NET, C# Snippets, General, Software
Comments Off
Determine if an assembly is a debug or release build
*This code originally came from another blog, although it was written in VB over there. It has lost some elegance in the translation, but I needed a very quick solution this afternoon, and I needed it in C#, so here … Continue reading
Posted in .NET, C# Snippets, Software
1 Comment
Sending an HTTP POST request to a web server
ASCIIEncoding encoding = new ASCIIEncoding(); string post_url = “http://172.16.24.44/postdata.php”; string poststring = “monkeys=blue\&trousers=black”; byte[] data = encoding.GetBytes(poststring); HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(post_url); httpRequest.Method = “POST”; httpRequest.ContentType=”application/x-www-form-urlencoded”; httpRequest.ContentLength = data.Length; Stream newStream=httpRequest.GetRequestStream(); newStream.Write(data,0,data.Length); newStream.Close(); HttpWebResponse response = (HttpWebResponse)httpRequest.GetResponse (); Stream receiveStream = … Continue reading
Posted in C# Snippets
Comments Off
Catch key presses in a Windows Forms application
Simple enough to do. Set the “KeyPreview” property of the form to “True” Create a KeyUp event handler, eg private void Form1_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e) { if(e.KeyCode == Keys.F12) { // Do something here } } Wire the event handler … Continue reading
Posted in C# Snippets
Comments Off
Sharepoint portal connection strings
How to pull connection string details out of a Sharepoint portal site. using System; using Microsoft.SharePoint.Portal; using Microsoft.SharePoint.Portal.Topology; namespace SPConnStrings { /// /// Summary description for Class1. /// class Class1 { /// /// The main entry point for the application. … Continue reading
Posted in C# Snippets
Comments Off
Sharepoint permissions and web parts
There is a strong argument against doing things like this, but there are times when you just have to bite the bullet and grant full access permissions to certain web parts without having to install them to the GAC. Here’s … Continue reading
Posted in C# Snippets
Comments Off
WMI Out Of Memory issues
I have been working on an automated way of deploying BizTalk assemblies, orchestrations and bindings without having to use NAnt or MSBuild this week. It has thrown up a problem that lots of people must have if they are doing … Continue reading
Posted in BizTalk, C# Snippets
Comments Off
Process.Start and required input
I had an issue with Process.Start today. I was trying to call an executable that requires the user to confirm the action with a keystroke, in this case “y”. As far as I am aware, there is no mechanism within … Continue reading
Posted in C# Snippets
Comments Off