Thursday, August 28, 2008

Fixing page layout URLs after importing a publishing site in SharePoint

Sometimes when you importing a publishing site in sharepoint, you may failing to copy some pages. If you looked at the page in the pages library the name of the layout was correct, but the link pointed to a different site(URL was pointing to the site from which I originally imported the site, but only some pages were broken). This problem may generate error "Value does not fall within the expected range".

Fixing the PageLayout URLs
A console application which looked at each of the pages and modified the link to the layout.
Code To do this action is:

private static void FixPages(SPWeb oWeb)
{
try
{
if (!PublishingWeb.IsPublishingWeb(oWeb)) return;
PublishingWeb pw = PublishingWeb.GetPublishingWeb(oWeb);
SPListItemCollection oList = pw.PagesList.Items;
string sSiteUrl = oWeb.Site.Url;
foreach (SPListItem oPageItem in oList)
{
string s = (string)oPageItem[FieldId.PageLayout];
if (!s.StartsWith(sSiteUrl))
{

Console.WriteLine("Fixing " + oPageItem.Title + " (" + oPageItem.Url + ")");
oPageItem[FieldId.PageLayout] = sSiteUrl + s.Substring(s.IndexOf("/", 9));
oPageItem.SystemUpdate();
}
}
foreach (SPWeb oSubWeb in oWeb.Webs)
{
Console.WriteLine("Processing " + oSubWeb.Title + "...");
FixPages(oSubWeb);
oSubWeb.Dispose();

}
}
catch (Exception ex)
{
Console.WriteLine("Layout fix failed at site: " + oWeb.Title);

Console.WriteLine(ex);
}
}

Running this application against the development site found a number of pages where the layout was broken and fixed up the link. Running it for a second time confirmed all the layout URLs were fixed.

MOSS Page Setting Error - Value does not fall within the expected range

We are getting error “Value does not fall within the expected range” when try to change the “Page Setting” in MOSS 2007. Yes, again same error message as in here (In fact, this error occurs is various scenarios). This error only happens when you copy an aspx page using SharePoint designer from one server to another severs (development server to production server). Once you try to edit the Page Setting, the error will occurs. We did some googling around but no luck. Some sites mention that the page is link to the old Page Layout’s URL and we are not able to change it since we cannot access the page setting. But, there are a workaround where you can solve it! Here are the steps:

  1. You cannot copy and paste the aspx page using SharePoint designer. First, export the aspx page using SharePoint designer to a physical file.
  2. Open the aspx page with notepad and search on the “mso:PublishingPageLayout”. You will notice your development portal URL is there.
    http://xxxdevelopmenturl/_catalogs/masterpage/BlankWebPartPage.aspx, Blank Web Part Page
  3. Replace your development URL (xxxdevelopmenturl) to the production URL and save it.
  4. Open your production site with SharePoint Designer and import the modified aspx page.

That’s all. You should able to change the page setting without any error. Do note that if you are using reporting services in the aspx page, you can replace all the report’s URLs too. In that case, you do not need to reconfigure all the web parts again. This saves us a lot of effort since our aspx page contains more than 25 web parts. It will take us hours to reconfigure the report URL and parameters.

Tuesday, July 29, 2008

SharePoint 2007 File Not Found Problem

Many People faced File Not Found Problem When they deployed SharePoint 2007 Site. When I investigated this problem found many common reasons.
  1. Declare physical folder with same name with sharepoint virtual folders.
  2. Missing deploying physical files features, delegate controls, user controls, etc.
  3. Didn't give a physical files suitable permissions.
  4. Missing deploying custom templates.
  5. Didn't publish content files masterpages, layouts, pages, stylesheets.
    Note: To discover this problem:
    a. Change Master page from sitesettings to standard masterpage
    b. If same error already exists republish layout.[checkout, checkin, publish layout]
    c. If same error already exists validate existing physical controls, refrence dlls.
    d. If error doesn't exists when you changed master page use your masterpage do same b,c with master page.
  6. Didn't deploy dependence files or sdks (refrence files of your dlls)

How to create your own custom 404 error page and handle redirect in SharePoint 2007 (MOSS)?

People alway ask how to use their own 404 file not found error page vs. the generic one from IE in MOSS environment. The following example catches the 404 error and sends users to a redirect page.

Here's the steps:

  1. In your MOSS server, make a copy of
    %systemdrive%\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\LAYOUTS\1033\sps404.html
    and call it my404.html
  2. Create a Virtual Directory in IIS under your MOSS root web application. For example /errors
  3. Create your own redirect aspx page, for example /errors/my404redirect.aspx and code your redirect logic in there. This is a normal asp.net page.
  4. In my404.html, make the following change:

    STSNavigate("/errors/my404redirect.aspx?oldUrl=" + requestedUrl);
  5. Create a Console Application and insert the following code and run it in MOSS server

System.Uri webApplicationUri = new Uri(http://MyMOSSServer/);
SPWebApplication webApplication = SPWebApplication.Lookup(webApplicationUri);
webApplication.FileNotFoundPage = "my404.html"; //*note
webApplication.Update();

*Note: By default this is set to null. FileNotFoundPage needs to point to a html file that lives in %systemdrive%\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\LAYOUTS\1033. The file needs to be html only.

6. Now when you browse to a page that doesn't exist, you should expect to be brought to the redirected page.

*Another note:
In IE there's a "Show friendly HTTP error messages" setting which is ON by default in Internet Options->Advanced. With this setting on, sometimes your custom error page is not displayed. In order to override this setting, both my404.html and /errors/my404redirect.aspx from the above steps need to be larger than 512 bytes in size. Refer to the following KB about this setting: http://support.microsoft.com/kb/218155
* This seems to be working within a site collection context only, i.e. http://MyMOSSServer/sites/siteA if sites is a wildcard inclusion managed path and siteA doesn't exist in MOSS then this URL will NOT trigger the custom 404 error page set to SPWebApplication.FileNotFoundPage property.

Also look at SharePoint Smart 404 Feature in codeplex
http://www.codeplex.com/sharepointsmart404
It will give you advanced features

Tuesday, July 15, 2008

How to remove a bad webpart from a page?

Previously, I added a poorly written webpart to my default.aspx page. The consequence of this action is that you aren't able anymore to load the page. In this case, the only thing you have to do is to remove the webpart. Removing the webpart in the webpart gallery doesn't solve this.
Resolution:
Append ?Contents=1 to the webpart page's URL to display the Webpart Maintenance Page. On that page you can delete the malefactor.
Example: http://moss/default.aspx?contents=1

Monday, July 14, 2008

SSL on selective pages in MOSS

If you want to apply SSL on some selective pages on moss site. When you obtained the certificate and assigned the certificate to the site. when tried to browse the site You will got the error msg: that site has to be browsed using Https:// When try to browse the site I got page not found error.

One possible solution is to untick the Require secure channel (SSL) option in IIS, and manually forcing a SSL using HTTP Module.

public class HttpModule:IHttpModule
{
public void Dispose()
{
//dispose function required to declare for HttpModule class
}
public void Init(System.Web.HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
}
void context_BeginRequest(object sender, EventArgs e)
{
RedirectSSL(System.Web.HttpContext.Current.Request.Url.PathAndQuery);
}
public void RedirectSSL(string pageURL)
{
//get the collection of the pages requiring SSL and not requiring SSL
//check for the current page exists in the group of pages requiring SSL
//if page is found in ssl group then redirect using https:// otherwise redirect with http://
bool found = false;
string sslPages = System.Configuration.ConfigurationSettings.AppSettings["SSLPages"];
char[] separator;
separator = new char[] { ',' };
string[] pages;
pages= sslPages.Split(separator);
for (int i = 0; i < pages.Length; i++)
{
if (pageURL.Contains(pages[i]))
{
found = true;
break;
}
}
if (found)
{
if (System.Web.HttpContext.Current.Request.Url.Scheme.ToString() == "http")
{
string sURL = System.Web.HttpContext.Current.Request.Url.ToString();
sURL = sURL.Replace("http://", "https://");
System.Web.HttpContext.Current.Response.Redirect(sURL);
}
}
else
{
if (System.Web.HttpContext.Current.Request.Url.Scheme.ToString() == "https")
{
string sURL = System.Web.HttpContext.Current.Request.Url.ToString();
sURL = sURL.Replace("https://", "http://");
System.Web.HttpContext.Current.Response.Redirect(sURL);
}
}
}
}

Tuesday, June 24, 2008

Deleting SSP now Marked unprovisioning

We want to delete the SSP and in the Central Admin, When clicked the delete button and the databases associated.
It has been running for a while and doesn't seem to be doing anything and it is marked (unprovisioning)

Solution:
Run Command
stsadm -o deletessp -title SharedServicesName -force