Thursday, 27 September 2007
Thursday, 13 September 2007
Long Text Fields in NHibernate
Tuesday, 4 September 2007
all abbreviated sys.*
sys.sql_logins Lists all users who can access the database.
sys.columns Lists all columns on database
sys.tables Lists all tables on database
sys.assemblies Lists all assemblies on database
sys.foreign_keys Lists all foreign keys on database
sys.triggers Lists all triggers on database
sys.procedures Lists all procedures on database
Friday, 10 August 2007
Regular Expression for National Insurance Number
^[A-CEGHJ-PR-TW-Z]{1}[A-CEGHJ-NPR-TW-Z]{1}\s?[0-9]{2}\s?[0-9]{2}\s?[0-9]{2}\s?[A-DFM]{0,1}$
Monday, 23 July 2007
How do i find the xpath of an XmlNode in c#?
/// <summary>
/// Gets an xpath to a node
/// </summary>
/// <param name="node">Node to get xpath for</param>
/// <returns>Xpath for node</returns>
private static string GetXPathToNode(XmlNode node)
{
if (node.NodeType == XmlNodeType.Attribute)
{
// attributes have an OwnerElement, not a ParentNode; also they have
// to be matched by name, not found by position
return String.Format(
"{0}/@{1}",
GetXPathToNode(((XmlAttribute)node).OwnerElement),
node.Name
);
}
if (node.ParentNode == null)
{
//Have root node - so return empty path
return "";
}
// the path to a node is the path to its parent, plus "/node()[n]", where
// n is its position among its siblings.
return String.Format(
"{0}/node()[{1}]",
GetXPathToNode(node.ParentNode),
GetNodePosition(node)
);
}
/// <summary>
/// Gets node position in relation to the child
/// </summary>
/// <param name="child">Child</param>
/// <returns>Position on parent</returns>
private static int GetNodePosition(XmlNode childNode)
{
for (int position = 0; position < childNode.ParentNode.ChildNodes.Count; position++)
{
if (childNode.ParentNode.ChildNodes[position] == childNode)
{
// need to add one as xpath index starts not at zero
return position + 1;
}
}
throw new InvalidOperationException("Missing Child Node");
}
Thursday, 12 July 2007
JavaScript popup window features
Here are the window.open options for the JavaScript window.open method, just set =1 if you want them included or =0 if you want them hidden.
status
Determines if you want the status bar at the bottom of the window to be shown
toolbar
This shows/hides the standard browser bar i.e. the back and forward buttons amongst others.
location
The location bar where you enter url’s.
menubar
This shows or hides the menu bar for the browser.
directories
This shows or hides the directories toolbar – i.e. whats new etc.
resizable
Enables/disables the user to resize the browser window.
scrollbars
Enable the scrollbars if the document takes up more area than the window
height
The height of the window in pixels. (i.e.: height='550')
width
The width of the window in pixels.
Tuesday, 19 June 2007
Granting permission to a user to create stored procedures on SQL Server 2005
GRANT ALTER ON SCHEMA::dbo TO
GRANT CREATE PROCEDURE TO
Friday, 15 June 2007
How to remove all empty nodes from an XmlDocument in c#
This is the xslt which does all the hard work...
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="no" indent="no"/>
<xsl:strip-space elements="*" />
<xsl:template match="*[not(node()) and not(./@*)]"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
And some code...
//Xsl to strip stylesheet
string strippingStylesheet = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"><xsl:output omit-xml-declaration=\"no\" indent=\"no\"/><xsl:strip-space elements=\"*\" /><xsl:template match=\"*[not(node()) and not(./@*)]\"/><xsl:template match=\"@* | node()\"><xsl:copy><xsl:apply-templates select=\"@* | node()\"/></xsl:copy></xsl:template></xsl:stylesheet>";
//Set up empty node stripper
XmlDocument stripper = new XmlDocument();
stripper.LoadXml(strippingStylesheet);
//Compile here
StringWriter output = new StringWriter();
XslCompiledTransform emptyNodeRemover = new XslCompiledTransform();
emptyNodeRemover.Load(stripper);
//Port output to string
StringWriter output = new StringWriter();
emptyNodeRemover.Transform(new XmlNodeReader(source), null, output);
output.Flush();
//Reload source with emptied nodes
source.LoadXml(output.ToString());
output.Close();
output.Dispose();
Friday, 18 May 2007
Adding columns dynamically to a data grid control
make sure the autogenerate on the data grid is switched off.
dataGrid1.AutoGenerateColumns=false;
then loop over the columns in the data source table.
foreach (DataColumn dc in dataTable.Columns)
{
BoundColumn newColumn = new BoundColumn();
newColumn.DataField = dc.ColumnName;
newColumn.HeaderText =
dataGrid1.Columns.Add(newColumn);
}
etc.
If you autogenerate the columns then the columns collection on the data grid will have no items.
Tuesday, 24 April 2007
A Regular Expression for a Strong Password
(?=^.{8,}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$A strong password is defined here as
1) Containing at least 1 upper case letter
2) Containing at least 1 lower case letter
3) Containing at least 1 number or special charachter
4) Containing at least 8 characters
