-
Archives
- February 2012
- January 2012
- September 2011
- May 2011
- April 2011
- September 2010
- 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
Manage IIS Security from a C# Assembly
I have discovered over the past couple of days that it is possible to control many aspects of IIS behaviour from a .NET assembly (in this case I will be using C# as the underlying language), by using the System.DirectoryServices … Continue reading
Posted in C# Snippets
Comments Off
Exclude named child nodes in XPath
To select all subnodes of a record, except for named exclusions, use the following XPath syntax: /rootNodeName/*[not(self::excludeChildName1)] or for multiple exclusions : /rootNodeName/*[not(self::excludeChildName1)][not(self::excludeChildName2)]
Posted in C# Snippets
Comments Off
Adding a “Please wait” message to long form submissions
I have a couple of forms on the company SharePoint Portal site that take a few seconds to submit. In the back end, they link into our financial packages, and rely on the external application to do some of the … Continue reading
Posted in C# Snippets
Comments Off
Hiding Columns in a dynamic DataGrid
resultDataGrid is populated from resultDataSet, which is populated directly from SQL. private void formatDataGridColumns() { for(int i=0;i<resultdataset .Tables[0].Columns.Count;i++) { BoundColumn objbc = new BoundColumn(); objbc.DataField = _ resultDataSet.Tables[0].Columns[i].ColumnName; objbc.HeaderText = _ resultDataSet.Tables[0].Columns[i].ColumnName; resultDataGrid.Columns.Add(objbc); objbc.Visible = false; if (objbc.HeaderText == _ … Continue reading
Posted in C# Snippets
Comments Off
Check if a file exists on a remote web server (by http)
using System.Net; WebRequest wrq = WebRequest.Create_ ("Http://www.example.com/fileToTest.htm"); bool fileExists = false; try { WebResponse wrs = wrq.GetResponse(); fileExists = true; } catch { }
Posted in C# Snippets
Comments Off
Get SharePoints Database names and connection strings.
C Sharp source code for grabbing database details in sharepoint Using Sharepoint’s internal mechanisms, it is possible to retrieve the database name and connection string for the content databases that power a site. The code in the attached file uses … Continue reading
Posted in C# Snippets
Comments Off
Conditional methods
To create methods that will only be called in a debug build of your application, you can use the following syntax : [Conditional( "DEBUG" )] private void SetDebugVariables() { connect ionString = “datasource=developmentDB;SSPI=true;initial catalog=development”; Trace.WriteLine(“Called in debug build”); } One … Continue reading
Posted in C# Snippets
Comments Off
Splitting a string to an array
string delimiters = " .,;:"; char [] delimiter = delimiters.ToCharArray(); string [] GotValues = Returned.Split(delimiter,2);
Posted in C# Snippets
Comments Off
Using XPath to narrow results from an XML file
// These two lines read config setting from the app.config file. filename = ConfigurationSettings.AppSettings["inputfile"]; filter = Configu rationSettings.AppSettings["filter1"]; XmlDataDocument myDocument = new XmlDataDocument(); myDocument.Load(filename); XmlNodeList myList = myDocument.SelectNodes(“//item[@class='" + filter + "']/*”); for (int i=0; i < myList.Count; i++) { … Continue reading
Posted in C# Snippets
Comments Off
Create a DataSet from a Stored Procedure
SqlConnection myConn = new SqlConnection(ConnectionString); SqlDataAdapter da = new SqlDataAdapter(); ds.SelectCommand = new SqlCommand(“GetByOffice”,myConn); da.SelectCommand.CommandType=CommandType.StoredProcedure; SqlParameter myParam = new SqlParameter(“@Office”,SqlDbType.VarChar,50); myParam.Direction=ParameterDirection.Input; myParam.Value = textBox1.Text; da.SelectCommand.Parameters.Add(myParam); DataSet ds = new DataSet(); da.Fill(ds,”results”); dataGrid1.DataSource = ds.Tables["Results"]; ds.WriteXml(“result.xml”,XmlWriteMode.WriteSchema);
Posted in C# Snippets
Comments Off