Since I started working with sharepoint 2007 I was puzzled by this bug, and recently I asked more people how said they have that too. The problem happens when you use the API to create a site out of a template that has the publishing feature activated in it. The site is created ok, but the first user to open the site will see a very odd tab and quick-launch:
So far, I have no explanation, but I have a workaround. Make a call to the site in the code. I know - this adds process time and resources, but it beats having your users ask you about the "error tab".
In your code, add the following function, and call it just after the site creation code:
public static void OpenUrl(string url)
{
try
{
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
request.UseDefaultCredentials = true;
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
}
catch(Exception ex) { //do something with the error }}
Here is an example how to use this function:
public static void CreateSite(SPWeb parentWeb)
{
try
{ //get the template for the site using the GetWebTemplate function I wrote
SPWebTemplate template = SharePointFunctions. GetWebTemplate(parentWeb, this.SiteTemplateName,
ConfigVariables.SitesLCID);
//create the site using the class properties
newWeb = parentWeb.Webs.Add(this.ShortName,
this.SiteTitle,
this.SiteDescription,
ConfigVariables.SitesLCID,
template, false, false);
OpenSiteHomePage(newWeb.Url);
}
catch(Exception ex) { //do something with the error }}
Tuesday, October 27, 2009
Workaround - "Error" in navigation when creating a publishing site from code
Posted by Rami Reddy Annapu Reddy at 1:55 AM
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment