Accessing embedded xml file using C#

I have recently been embedding xml files into assemblies so the information can be accessed in code.

This is how I get a reference to the current assembly where the code and xml file is residing

Assembly currentAssembly = Assembly.GetExecutingAssembly();

I invoke the method to get my xml file by doing the following:

Stream stream = currentAssembly.GetManifestResourceStream(this.GetType(), “ValidationRules.xml”);

I create a new XmlDocument and load the content of the xml file into there:

XmlDocument doc = new XmlDocument();
doc.Load(stream);

Given my xml is kind of like this:

<?xml version=”1.0″ encoding=”utf-8″ ?>

<Fields>

<Field>
<Name>Question 1a</Name>
<ValidationRule>Mandatory</ValidationRule>
<ValidationMessage>The Question 1a field cannot be empty</ValidationMessage>
<DependentFields>Question 2a</DependentFields>
</Field>
<Field>
<Name>Question1b</Name>
<ValidationRule>Mandatory</ValidationRule>
<ValidationMessage>Question 1b cannot be empty</ValidationMessage>
<DependentFields>Question2b</DependentFields>
</Field>

</Fields>

Depending on the structure of your xml, I would iterate through the element nodes using a foreach. I would go through each element by doing the following:

 foreach (XmlElement xmlField in doc.SelectNodes(“/Fields/Field”))
{
string fieldName = xmlField.SelectSingleNode(“Name”).InnerText;
string dependentFields = xmlField.SelectSingleNode(“DependentFields”).InnerText;
}

I can now use the data from the xml file to do other processing in my code.

The file or folder name contains characters that are not permitted

This is a very misleading error message to get, especially when the cause and solution has NOTHING related to what the message is referring to.

I came across this error while attempting to deploy my site definition. I added a few things to my site definition, one of these was a aspx page referring to my master page.

The error:

<%@ Page language=”C#” MasterPageFile=~masterurl/custom.master” …../>

The fix:

<%@ Page language=”C#” MasterPageFile=”_catalogs/masterpage/custom.master” …../>

Done!

User Code Host Service keeps stopping

I recently came across a this error a few times on different SharePoint 2010 environments. Initially, I came across the error “User Code Host Service is too busy…” , then I stopped and started the User Code Host service from Central Administration. This then caused the error message telling me that the there was “No available Sandbox code execution server  could be found”.

I then looked into the error logs and found some errors about the User Code Host service and Performance logging. I opened the SharePoint log file, and scrolled down to the bottom of the file. Then I did a CTRL+F for “Perf”. I then found the error relating to starting the code host service and how the service has stopped.

 

And NO, STOPPING AND STARTING THE BLOODY USER CODE HOST SERVICE IN CENTRAL ADMINISTRATION DOES NOT FIX THIS PROBLEM!

 

Resolution:

I came across these this fix that resolved the issue of the User Code Host Service keeps stopping:

         http://support.microsoft.com/kb/2021539

 

This KB Article below was already done, but might be helpful for you too.

http://support.microsoft.com/kb/2509267

Done.