Ashley
Blog - Robert Bogue [MVP]
Rob's Notebook
SharePoint Calendar
Thor Projects LLC - Welcome : Blog - Robert Bogue [MVP]
Tuesday, September 15, 2009

Mentions: K2 SharePoint Governance Series Interview

I had the pleasure of being interviewed by my buddy Chris Geier at K2 for a new series he's starting on SharePoint Governance. You can find his introduction to the series here and the download for the interview here. Check it out.


Categories: Professional | 0 Comments
 
Wednesday, September 09, 2009

XML, XPath, and Namespaces

One of the problems that I had early on with XML when I started was that I couldn't figure out an easy way to handle namespaces when I was processing XML. SharePoint and other Microsoft technologies like InfoPath make extensive use of namespaces. For instance, if you right click a field in InfoPath and select Copy XPath you'll get something in your clipboard that looks like: /my:TestForm/my:Repeating/my:Message --Frankly, that's not all that complex of an XPath statement, except that it has a namespace in it. In this case we don't know what "my" refers to. That made it easier for me to transform the XPath statement into /*[local-name()='TestForm'/*[local-name()='Repeating']/*[local-name()='Message']. It's frankly not that big a deal except that it's somewhat tedious. This allows me to call XMLDocument.SelectNodes(string xPath) instead of XMLDocument.SelectNodes(string xPath, XmlNamespaceManager nsmgr) which was good because I didn't have a namespace manager and I didn't know how to create one easily. However, I ran into a new problem that my quick solution didn't allow me to get around. I wanted to add a set of new nodes to an existing document -- in that case I couldn't ignore namespaces any longer.

After a bit of gnashing of teeth I realized that I can create a XmlNameSpaceManager pretty easily by looking at the attributes of my document element (DocumentElement) node. Take a look at this code:

XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);

foreach (XmlAttribute attr in doc.DocumentElement.Attributes)

{

if (attr.Name.IndexOf("xmlns:") == 0)

{

string prefix = attr.Name.Replace("xmlns:", "");

string nsUri = attr.Value;

nsmgr.AddNamespace(prefix, nsUri);

}

}

In this snippet I use the document element attributes to create my namespace manager -- thus I can use the same namespace prefixes as are in use in the document itself. (Forgive me for using .Replace() rather than .Substring() - I ultimately decided it was more readable.) Taking this scenario a bit farther, with the namespace manager I can create a node of <my:Message /> with:

XmlElement ele = doc.CreateElement("my", "Message", nsmgr.LookupNamespace("my"));

 

This abstracts out what the namespace actually is so that I can just reference the existing prefixes. With the element created I can set its InnerText property and then use XmlNode.AppendChild() to append the new element into my document.

Since it's easy to create XmlNameSpaceManager objects now ... I might have to forget my *[local-name()='foo'] trick... although it's still useful when I'm leveraging Xml editing tools and I don't have namespace support in them.


Categories: Professional | 0 Comments
 
Tuesday, September 08, 2009

MOSS Built In Site Column Table

I needed to get the site column IDs for some of the built in site columns and while there are several places on the Internet where you can find the technique for pulling them out of the URL when editing a field that was going to be a bit tedious for what I was going to do so I wrote a quick utility that would dump out the site columns to a text file. The resulting XLS file is available here.

I hope that it helps if you're looking for a specific field IDs and you don't want to URL decode them.


Categories: Professional | 0 Comments
 
Saturday, September 05, 2009

Moving SharePoint Development Forward – p&p SPG

One of the things I like best about my work is that I get to work with some great people doing fun and interesting things. I can honestly say that in our small part of the universe we manage to push the ball forward. I've had the pleasure of speaking at the SharePoint Best Practices Conference as well as other events – to try to share the things we've learned about how to develop scalable, maintainable, robust applications on the SharePoint Platform. One of the things that I have the most fun with is helping the Microsoft Patterns and Practices group put together their SharePoint Guidance. The first iteration we worked on basic collaborative applications. The second iteration (this one) we took a look at web content management scenarios and line of business integration.

Certainly I don't expect that everyone can use all of the work that was done here – however, I expect that it's more than worth your time to take a peruse through the materials. I know you'll find at least one thing that you didn't know or didn't think of before. I know that because there were tons of things that I didn't know about the platform – or hadn't considered – that I learned.

Go check out the latest version of the SharePoint Guidance from p&p


Categories: Professional | 1 Comment