Friday, August 28, 2009

Hello All,

I wanted to create publishing pages that is aspx pages in the Pages library. After lots of tricks here and there, finally managed to do it through the following piece of code:
using Microsoft.SharePoint.Publishing;
PublishingSite pSite = new PublishingSite(siteurl);
SPContentType projectCT = pSite.ContentTypes[];
PageLayoutCollection pageLayouts = pSite.GetPageLayouts(projectCT, true);
PageLayout projectLayout = pageLayouts[];
PublishingWeb pWeb = PublishingWeb.GetPublishingWeb(hlfWeb);
PublishingPageCollection pageCollection = pWeb.GetPublishingPages();
PublishingPage projectPage = pageCollection.Add("page1.aspx", projectLayout);
SPListItem projectPageItem = projectPage.ListItem;
projectPageItem["Title"] = "page1";
//other properties can be given here as well.

Requirement was such that I had to create these pages in specific folders. A simple way out:
PublishingPage projectPage = pageCollection.Add(projectFolder.ServerRelativeUrl + "/" + projectDetail.ProjectTitle + ".aspx", projectLayout);

Where projectFolder is the folder in the library.

Hope it saves on time for somebody with similar problem.
Happy Sharepointing!!

Monday, August 3, 2009

MOSS Search - Content for this URL is excluded

I recently faced this strange issue, some of the content in a site was not getting searched, no error. I executed full crawl several no. of times, but without success. Then I saw this warning in the crawl logs: "Content for this URL is excluded by the server because a no-index attribute". Well for some items that were not being crawled the reason was my crawl rule was such, but for others like subsites itself could not understand what could be the cause.
Then I looked into search visibility of those sites, and found that indeed the option for this web to appear in search results was set to NO. How simple, but it took me 3 hours to come to that setting :)

Sometimes critical problems have simple solutions!!!