How To Escape XSL Parameters In Sharepoint Designer Site Pages



TODO:

Have you ever had data from Sharepoint display as for instance '&' rather than '&'

 

SOLUTION:

The solution is simple, just escape the XSL Parameter as follows:

<xsl:value-of select="@MyDataParam" disable-output-escaping="yes" />

 

NOTES:

There are no notes on this topic.

How To Fix Blank Page In Sharepoint Central Admin Due To 500 Internal Error



TODO:

Have you ever had an Internal 500 error when you open Sharepoint Central Admin?

 

SOLUTION:

Step 1, is to enable failed request tracking for the Central Admin Site.  This is done by opening IIS, clicking on the Central Admin Site, and choosing Failed Request Tracking.

Step 2, is to open Central Admin again, and view the failed request log.

Step 3, in my case, the Sharepoint14Module was causing an issue.  "Module 'Sharepoint14Module' could not be found' was the message.

Step 4, the message in step 3 pointed me to the ApplicationHost.config file.  Sure enough, that module was pointed to an App Pool that did not exist.

Step 5, change the App Pool to a valid App Pool, and save the ApplicationHost.confg file.

All should be well, assuming your issue was due to a module error.

 

NOTES:

The key to this post, is that failed request tracking saved the day.  I was not getting anything in the Sharepoint log, or the IIS log at all.  By enabling failed request tracking, I was able to pinpoint the error that was really happening, and fix it.

How To Fix 'Recycle IIS Application Pool: Provider load failure' With Visual Studio And Sharepoint



TODO:

Have you ever received the dreaded 'Recycle IIS Application Pool:  Provider load failure' message when trying to deploy and run a Sharepoint Solution from Visual Studio?  No need to reboot, just put the following lines in a .bat file, and run it as Administrator.

 

SOLUTION:

net stop SPTimerV4
net start SPTimerV4
net stop SPUserCodeV4
net start SPUserCodeV4
net stop SPAdminV4
net start SPAdminV4
REM net stop TrustedInstaller
REM net start TrustedInstaller
REM net stop Winmgmt
REM net start Winmgmt
REM net stop W3SVC
REM net start W3SVC
iisreset
 

NOTES:

If that does not work, try removing the REM statements, and it should work..

How to Fix: The web server process that was being debugged has been terminated by IIS. this can be avoided by configuring application pool setting in IIS. see help for further details.



TODO:

Have you been debugging an ASP .Net application and get the error:

"The web server process that was being debugged has been terminated by IIS. this can be avoided by configuring application pool setting in IIS. see help for further details."

 

 SOLUTION:

Go to the advanced settings in your application pool and set Ping Enabled to false.

App Pool -> Advanced ->  Ping Enabled -> Set to false

 

NOTES:

There are no notes on this topic

How To Fix BOOTMGR Is Missing Error Message In VMWare / Windows



TODO:

Have you ever received the message "BootMgr is missing" error message, when booting to Windows from VMWare?  This is due to, or can be due to the Boot Partition not being marked as active.  The fix is easy, you just need GParted, and about 15 minutes of time. 

 

SOLUTION:

1.  Download GParted here

2.  Mount the GParted Live iso in VMare.  To do this, go to VMWare -> Settings -> CD

     2.1   Next choose "Select disk or disk image"

     2.2  Select the GParted ISO.

3.  Restart VM

4.  In GParted select to Boot Partition, choose "Manage Flags", and select "boot".  This makes it the Boot Partition again.

5.  Close GParted, and restart VM.  Windows will now boot. 

 

NOTES:

There are no notes on this topic.

How To Get The Public Key Of An Assembly In Visual Studio



 TODO:

Have you ever needed the public key for an assembly that is the output of a project in Visual Studio?

 

SOLUTION:

The solution is to tie the strong name tool (sn.exe) to a menu item under External Tools in Visual Studio.  There is a working solution on this link.  I tried it and it does exactly what I needed it to do.  The public key is written to the output window!

 

NOTES:

There are no notes on this topic.

How To Create a Custom App.Config File With Nested Elements



TODO:

Have you ever wanted a custom config, that had nested elements in it?  For example, I need a config file like such:

 

App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="EmailServiceSettings" type="Donnie.Wishard.Configuration.EmailServiceSettings, EmailServiceSettings" />
  </configSections>

  <EmailServiceSettings Name="Test Site">
    <EmailServers>
      <Server Name="Local Server" IpAddress="127.0.0.1" />
    </EmailServers>
  </EmailServiceSettings>
</configuration>

 

And to accomplish that, you need the 2 pieces of code.

 

SOLUTION:

EmailServiceSettings.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace Donnie.Wishard.Configuration
{
    /// <summary>
    /// Email service settings configuation section
    /// </summary>
    public sealed class EmailServiceSettings: ConfigurationSection
    {
        #region Member Variables
        private static EmailServiceSettings settings = ConfigurationManager.GetSection("EmailServiceSettings") as EmailServiceSettings;
        #endregion
        
        #region Fields
        /// <summary>
        /// Settings Property
        /// </summary>
        public static EmailServiceSettings Settings
        {
            get { return settings; }
        }

        /// <summary>
        /// The Id
        /// </summary>
        [ConfigurationProperty("Name", DefaultValue = "", IsRequired = true)]
        public string Name
        {
            get { return(string)this["Name"]; }
            set { this["Name"] = value; }
        }
        
        /// <summary>
        /// The collection of services / methods
        /// </summary>
        [ConfigurationProperty("EmailServers", IsDefaultCollection=true, IsKey=false, IsRequired=true)]
        public EmailServersCollection EmailServers
        {
            get { return base["EmailServers"] as EmailServersCollection; }
        }
        #endregion
        #region Methods
        #endregion
    }  
    /// <summary>
    /// The EmailServersCollection class
    /// </summary>
    public sealed class EmailServersCollection : ConfigurationElementCollection
    {
        #region Member Variables
        #endregion
        #region Fields
        /// <summary>
        /// Create method
        /// </summary>
        /// <returns></returns>
        protected override ConfigurationElement CreateNewElement()
        {
            return new EmailServerElement();
        }
        /// <summary>
        /// Get element key
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        protected override object GetElementKey(ConfigurationElement element)
        {
            return((EmailServerElement)element).Name;   //key is method name for us
        }
        /// <summary>
        /// Name element
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        new public EmailServerElement this[string name]
        {
            get { return(EmailServerElement)base.BaseGet(name); }
        }
        /// <summary>
        /// Collection type setting
        /// </summary>
        public override ConfigurationElementCollectionType CollectionType
        {
            get
            {
                return ConfigurationElementCollectionType.BasicMap;
            }
        }
       /// <summary>
        /// Index element
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public EmailServerElement this[int index]
        {
            get { return(EmailServerElement)base.BaseGet(index); }
        }
        /// <summary>
        /// Override the name
        /// </summary>
        protected override string ElementName
        {
            get
            {
                return "Server"; //force name of Server for elements
            }
        }
        #endregion
        #region Methods
        #endregion
    }

    /// <summary>
    /// The EmailServerElement class
    /// </summary>
    public sealed class EmailServerElement: ConfigurationElement
    {
        #region Member Variables
        #endregion
        #region Fields
        /// <summary>
        /// The Name
        /// </summary>
        [ConfigurationProperty("Name", DefaultValue = "", IsRequired = true)]
        public string Name
        {
            get { return (string)base["Name"]; }
            set { base["Name"] = value; }
        }
        /// <summary>
        /// The Method
        /// </summary>
        [ConfigurationProperty("IpAddress", DefaultValue = "", IsRequired = true)]
        public string Method
        {
            get { return (string)base["IpAddress"]; }
            set { base["IpAddress"] = value; }
        }
        #endregion
        #region Methods
        #endregion
    }
}

 

Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Donnie.Wishard.Configuration
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Donnie.Wishard.Configuration.EmailServiceSettings s = Donnie.Wishard.Configuration.EmailServiceSettings.Settings;
            }
            catch (Exception x)
            {
                x = x;
            }
        }
    }
}

 

NOTES:

1.  Create a console application, and replace your Program.cs contents with the contents above.

2.  Create a class library in the solution, and put the EmailServiceSettings.cs code in it

3.  Add an app.config to the console application, using the config data from the top.

How To Add A Document As An Attachment To A New SharePoint List Item In C#



TODO:

Have you ever wanted to add a file, as an attachment to a new item in a SharePoint list?

 

SOLUTION:

        /// <summary>Add the contents of a file to a document library</summary>
        /// <param name="DocumentData">byte[] of the document data</param>
        /// <param name="SharePointUrl">The URL to the sharepoint server</param>
        /// <param name="SharePointSite">The name of the site the document library resides</param>
        /// <param name="DocumentLibrary">The name of the document library</param>
        /// <param name="MetaData">Any meta data you want to add.  For instance if there are other columns, you can specify them here.</param>
        /// <param name="OverWriteFile">Overwrite flag.  true or false, self explanatory</param>
        /// <returns></returns>
        public bool AddFileToList(byte[] DocumentData, string SharePointUrl, string SharePointSite, string List, Hashtable MetaData)
        {
            try
            {
                //get the site
                using (SPSite mysiteCollection = new SPSite(SharePointUrl))
                {
                    // Alternately you can use oSite.RootWeb if you want to access the main site
                    // but we will just do a find so we do not need to worry about levels
                    SPWebInfo webinfo = mysiteCollection.AllWebs.WebsInfo.Find(delegate(SPWebInfo w) { return w.Title.ToUpper() == SharePointSite.ToUpper(); });
                    //get the site by title (need to because name could be site/site...)              
                    using (SPWeb rootSite = mysiteCollection.AllWebs[webinfo.Id])   //now get the web by GUID
                    {
                        SPList incompleteList = rootSite.Lists[List];               //the list by display name
                        SPListItem newItem = incompleteList.Items.Add();            //get the item from the file just uploaded

                        //now add each item to the properties
                        if (MetaData != null)
                        {
                            //take each piece of meta data, and apply it to the item
                            foreach (object key in MetaData.Keys)
                            {
                                //newItem.Properties.Add(key, MetaData[key]);
                                newItem[key.ToString()] = MetaData[key];
                            }
                        }

                        newItem.Attachments.Add(string.Format("{0}.xml", Guid.NewGuid()), DocumentData);   //add attachments to the list item
                        newItem.Update();   //update the item
                    }
                }
                return true;
            }
            catch (Exception x)
            {
                return false;
            }
        }

 

NOTES:

The meta data are columns on the item.  You can populate those during the add, by passing them in in a Hashtable.

How To Add Document To A SharePoint Document Library C#



TODO:

Have you ever wanted to add a document to a SharePoint document library?  The below example, is a method that will allow you to do just that.

 

SOLUTION:

        /// <summary>
        /// Add the contents of a file to a document library
        /// </summary>
        /// <param name="DocumentData">byte[] of the document data</param>
        /// <param name="SharePointUrl">The URL to the sharepoint server</param>
        /// <param name="SharePointSite">The name of the site the document library resides</param>
        /// <param name="DocumentLibrary">The name of the document library</param>
        /// <param name="MetaData">Any meta data you want to add.  For instance if there are other columns, you can specify them here.</param>
        /// <param name="OverWriteFile">Overwrite flag.  true or false, self explanatory</param>
        /// <returns></returns>
        public bool AddFileToDocumentLibrary(byte[] DocumentData, string SharePointUrl, string SharePointSite, string DocumentLibrary, Hashtable MetaData, bool OverWriteFile)
        {
            try
            {
                //get the site
                using (SPSite mysiteCollection = new SPSite(SharePointUrl))
                {
                    //get web info by title (i need to do it this way)
                    SPWebInfo webinfo = mysiteCollection.AllWebs.WebsInfo.Find(delegate(SPWebInfo w) { return w.Title.ToUpper() == SharePointSite.ToUpper(); });
                    
                    //get the site by title (need to because name could be site/site...)              
                    using (SPWeb rootSite = mysiteCollection.AllWebs[webinfo.Id])   //now get the web by GUID
                    {
                        SPFile newFile = null;
                        SPFolder incompleteLibrary = rootSite.Folders[DocumentLibrary]; //the list by display name
                        
                        //now create a hash of our fields we want to set, and do it in one shot.
                        if (MetaData == null || MetaData.Count == 0)
                            newFile = incompleteLibrary.Files.Add(string.Format("{0}.xml", Guid.NewGuid()), DocumentData, OverWriteFile);  //add it to the library
                        else
                            newFile = incompleteLibrary.Files.Add(string.Format("{0}.xml", Guid.NewGuid()), DocumentData, MetaData, OverWriteFile);  //add it to the library
                    }
                }
                
                return true;
            }
            catch (Exception x)
            {
                return false;
            }
        }

 

NOTES:

In my case, I was only adding XML files.  Therefore you can change the file name generation to use an extension that is passed in potentially.

How To Update Each Item In A SharePoint List Or Document Library When A Feature Is Activated



TODO:

Have you ever created an Event Receiver, and you would like to have it fire for all items in a list?  To do this, I created a Feature, that upon activation, will open a list or document library, and call Update() on each item in the list.  That will cause the Event Receiver to fire, thus applying its logic to each item in the list.

 

SOLUTION:

/// <summary>
/// Feature activated method
/// </summary>
/// <param name="properties"></param>
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
       try
       {
           //check the context
           if (SPContext.Current == null || SPContext.Current.Web == null || string.IsNullOrEmpty(SPContext.Current.Web.Url))
               return;

           // Use using to make sure resources are released properly  
           using (SPSite mysiteCollection = new SPSite(SPContext.Current.Web.Url))
           {
               // Alternately you can use oSite.RootWeb if you want to access the main site  
               SPWebInfo webinfo = mysiteCollection.AllWebs.WebsInfo.Find(delegate(SPWebInfo w) { return w.Title == "My Site Name"; });  //get the site by title (need to because name could be site/site)
               SPWeb rootSite = mysiteCollection.AllWebs[webinfo.Id];  //now get the web by GUID
                    
               SPList oList = rootSite.Lists["My List Name"];         //the list by display name
               foreach (SPListItem oItem in InputList.Items)
               {
                     //now just update it, so the event reciever fires
                     oItem.Update();
               }
           }
       }
       catch (Exception x)
       {   
       }
 }

 

NOTES:

There are no notes on this topic