Quantcast
Channel: Website – Random Technical Thoughts
Viewing all articles
Browse latest Browse all 8

How to check if a project template exists

$
0
0

If you are creating sites based off custom project templates through code you should if the project template exists.  If you don’t and you try then SharePoint will through an error.

Here is a simple method that will return true or false if your project template exists.  You pass in the name of the project template you are looking for.

//Check if a site template already exists
        private static bool templateExists(string title)
        {
            using (SPWeb webSite = SPContext.Current.Web)
            {
                SPWebTemplateCollection collection = webSite.GetAvailableWebTemplates(Convert.ToUInt32(1033));

                foreach (SPWebTemplate list in collection)
                {
                    if (list.Title.ToLower() == title.ToLower())
                    {
                        return true;
                    }
                }
            }
            return false;
        }
[tweetmeme only_single=”false”]


Viewing all articles
Browse latest Browse all 8

Trending Articles