Thursday, October 23, 2008

SharePoint 2007 URL Quick List

The following is a list of SharePoint URLs to get to commonly used administrative functions on a MOSS or WSS v3 site. Not all links listed on this page are accessible to all user levels of a site. This is a quick list for speedy reference as compared to tracking down links through the admin screens or for faster jumping around sites within a site collection.

Add Web Parts Pane
url: ?ToolPaneView=2

Add to the end of the page URL; WILL ONLY WORK IF THE PAGE IS ALREADY CHECKED OUT

Create New Site Content
url: /_layouts/create.aspx

List Template Gallery
url: /_catalogs/lt

Manage Site Collection Administrators
url: /_layouts/mngsiteadmin.aspx

Manage Sites and Workspaces
url: /_layouts/mngsubwebs.aspx

Manage People
url: /_layouts/people.aspx

Manage User Permissions
url: /_layouts/user.aspx

Master Page Gallery
url: /_catalogs/masterpage
Also includes Page Layouts
Modify Navigation
/_layouts/AreaNavigationSettings.aspx

Recycle Bin
url: /_layouts/AdminRecycleBin.aspx

Site Column Gallery
url: /_layouts/mngfield.aspx

Site Content Types
url: /_layouts/mngctype.aspx

Site Content and Structure Manager
url: /_layouts/sitemanager.aspx

Site Settings
url: /_layouts/settings.aspx

Site Template Gallery
url: /_catalogs/wt

Site Usage Summary
url: url: /_layouts/SpUsageWeb.aspx

User Alerts
url: url: /_layouts/sitesubs.aspx

View All Site Content
url: /_layouts/viewlsts.aspx

Web Part Gallery
url: /_catalogs/wp

Web Part Page Maintenance
url: ?contents=1

Add to the end of the page URL
Workflows
url: /_layouts/wrkmng.aspx

Monday, October 13, 2008

Custom field type that can hold more than the 255

Many people ask me, they need to use field holds more than the 255 characters. They used MultiLine text. It worked fine with custom list but failed (generate error can't hold than 255 characters) with content type.
Many bloggers suggest to create custom field type, I tried this suggestion but gave me same result.
I found simplest solution Create Site Column of type MultiLine text, and set property UnlimitedLengthInDocumentLibrary to TRUE.
You can use tool Imtech Fields Explorer v1.5.0.0 to set this property.
download Imtech Fields Explorer v1.5.0.0

Friday, September 26, 2008

SharePoint 2007 Utilities

This is list of best tools to help you to administrate and support SharePoint 2007:

  1. SharePoint Manager 2007:
    The SharePoint Manager 2007 is a SharePoint object model explorer. It enables you to browse every site on the local farm and view every property. It also enables you to change the properties (at your own risk). This is a very powerfull tool for developers that like to know what the SharePoint holds of secrets.
  2. Download SharePoint Manager 2007

  3. Sharepoint Logging Spy
    Sharepoint Logging Spy is a real time diagnostic application for MOSS 2007 which allows a sharepoint administrator to view (and save to disk) the ULS Log & Event log entries from multiple machines in a sharepoint farm through a single console.

    Download Sharepoint Logging Spy
  4. SharePoint Content Deployment Wizard
    The SharePoint Content Deployment Wizard is a tool for SharePoint 2007 which provides the means to deploy the following content:
    - site collections
    - webs
    - lists
    - folders
    - list items (including files)

    Download SharePoint Content Deployment Wizard
  5. FaultyFeatureTool:
    The SharePoint FaultyFeatureTool is tool to discover any feature has a fault

    Download FaultyFeatureTool
  6. Imtech Fields Explorer v1.5.0.0
    Tool to simplify your work with Layouts, content types, sites columns
    for more information go to url

Download Fields Explorer

Unlimited length text field

SharePoint 2007 SPFieldMultiLineText is limited to 255 characters. How do we bypass this restriction?

We need to create a new field that inherits from SPFieldMultiLineText. and create your own FLDTYPES.XML file.

First We have to create custom field
public class CustomMultilineField : SPFieldMultiLineText
{
#region SPField Constructors
public CustomMultilineField(SPFieldCollection fields, string fieldName) : base(fields, fieldName)
{

}

public CustomMultilineField(SPFieldCollection fields, string typeName, string displayName) : base(fields, typeName, displayName)
{

}
#endregion

public new string GetFieldValueAsHtml(object value, SPListItem item)
{
string html = base.GetFieldValueAsHtml(value, item);
return html.Replace("CreateWebPage", "CreateCustomPage");
}

public override BaseFieldControl FieldRenderingControl
{
get
{
BaseFieldControl fieldControl = new CustomMultilineFieldField();
fieldControl.FieldName = InternalName;
return fieldControl;
}
}
}

Render a Control


public class CustomMultilineFieldField : NoteField
{
protected override void RenderFieldForDisplay(HtmlTextWriter output)
{
CustomMultilineField field = (CustomMultilineField) Field;
if (field != null)
{
if (field.CustomMultilineFieldLinking)
{
output.Write("<div class=\"ms-CustomMultilineFieldcontent\">");
output.Write(field.GetFieldValueAsHtml(ItemFieldValue, ListItem));
output.Write("<p></p></div>");
return;
}
}
else
{
return;
}
base.RenderFieldForDisplay(output);
}
}

Create a definition file

<FieldType>
<Field Name="TypeName">CustomMultilineField</Field>
<Field Name="ParentType">Note</Field>
<Field Name="TypeDisplayName">
CustomMultilineFieldField
</Field>
<Field Name="TypeShortDescription">
CustomMultilineFieldField supports custom page
</Field>
<Field Name="UserCreatable">FALSE</Field>
<Field Name="ShowInListCreate">FALSE</Field>
<Field Name="ShowInSurveyCreate">FALSE</Field>
<Field Name="ShowInDocumentLibraryCreate">FALSE</Field>
<Field Name="ShowInColumnTemplateCreate">FALSE</Field>
<Field Name="Sortable">FALSE</Field>
<Field Name="Filterable">FALSE</Field>
<Field Name="FieldTypeClass">IdeSeg.SharePoint.CustomMultilineFields.CustomMultilineField.CustomMultilineField,IdeSeg.SharePoint.CustomMultilineFields,Version=1.0.0.0, Culture=neutral, PublicKeyToken=...</Field>
</FieldType>

Tuesday, September 2, 2008

Programmatically Inherit Master Page and CSS in MOSS 2007

So recently I have been working on two small MOSS features:

  • Change the master page and stylesheet settings for a site
  • Staple the first feature to all site templates, so it is activated upon site creation

SharePoint Object Model:

  • SPSite is a Site Collection
  • SPWeb is a Site within a Site Collection

there are a couple of properties of the SPWeb object which we will be using:

  • [web_object].MasterUrl
  • [web_object].CustomMasterUrl
  • [web_object].AlternateCssUrl

These values are read/write, so you can set the values to your own strings and the values in the database will be changed accordingly.

Note: all of the following is done within the FeatureActivated function of a custom class inheriting from the SPFeatureReceiver class. Now let’s dive into some code (these are all different methods I tried to no avail)

Created some variables and hard coded the locations within the feature:

string MasterUrl = "/_layouts/custom.master";
string CustomMasterUrl = "/_layouts/custom.master";
string AlternateCssUrl = "/StyleLibrary/Custom/CSS/stylesheet.css";
SPWeb web = (SPWeb)properties.Feature.Parent;
try {
web.MasterUrl = MasterUrl;
web.CustomMasterUrl = CustomMasterUrl;
web.AlternateCssUrl = AlternateCssUrl;
web.Update();
}catch { }

Set the values of the current site to the values from the root site:

SPWeb web = (SPWeb)properties.Feature.Parent;
try {
web.MasterUrl = web.Site.RootWeb.MasterUrl;
web.CustomMasterUrl = web.Site.RootWeb.CustomMasterUrl;
web.AlternateCssUrl = web.Site.RootWeb.AlternateCssUrl;
web.Update();
}catch { }

Set the values of the current site to the values from it’s parent site:

SPWeb web = (SPWeb)properties.Feature.Parent;
try {
web.MasterUrl = web.ParentWeb.MasterUrl;
web.CustomMasterUrl = web.ParentWeb.CustomMasterUrl;
web.AlternateCssUrl = web.ParentWeb.AlternateCssUrl;
web.Update();
}catch { }

None of these methods, upon going to the “Site Master Page Settings” page within a browser, showed the little radio button next to “Inherit site master page from parent of this site” as being checked. They did correctly set the master page and stylesheet links, but if I went to a parent site and changed the master page, the master page did not get changed on the site *unless* the “inherit” radio button was selected.

I decided to take this to the Content Database for the portal in which I was working. Looking in the dbo.Webs table, I found that if the “Inherit” radio button is selected, there are still values in the DB for AlternateCssUrl, MasterUrl, and CustomMasterUrl. Running the above code, would put the same values in these fields, but the “Inherit” radio button would not be selected. I then performed the following steps:

  • Copy a row (one site) from the database to a text file
  • Change each of the 3 settings (Site Master, System Master, and Alternate CSS) from “Inherit” to “Specify a …”
  • Copy the same row from the database to the second row of the text file
  • Change each of the 3 settings back to “Inherit”
  • Copy the same row from the database to the third row of the text file
  • Change each of the 3 settings back to “Specify a …”
  • Copy the same row from the database to the fourth row of the text file

I then moved the side-scroll-bar all the way to the right (to confirm something in each lines was different) and they did not end at the same character, so I went to the beginning and compared vertically until I found different characters. There were a total of 3 instances of different characters (all 3 instances had the same characters) all within the same field, ‘MetaInfo’. These values were:

  • “Inherit”: 547275
  • “Specify a …”: 46616C73

Going back to the SharePoint Object Model, I discovered that there are two member properties to the SPWeb object which seem to correlate to site properties: Properties and AllProperties. I then tossed together a quick console app to output all Key/Value pairings for these two collections, and this is what came out:

  • SPWeb.Properties (C# type SPPropertyBag)
    • vti_extenderversion: 12.0.0.4518
    • vti_associatevisitorgroup: 4
    • vti_defaultlanguage: en-us
    • vti_associategroups: 5;4;3;6;7;8;9;10;11;14;15;17;18;28
    • vti_associateownergroup: 3
    • vti_associatemembergroup: 5
  • SPWeb.AllProperties (C# type Hashtable)
    • vti_extenderversion: 12.0.0.4518
    • __InheritsCustomMasterUrl: False
    • vti_associatevisitorgroup: 4
    • vti_categories: Business Competition Expense\ Report Goals/Objectives Ideas In\ Process
    • Miscellaneous Planning Schedule Travel VIP Waiting
    • vti_associatemembergroup: 5
    • vti_defaultlanguage: en-us
    • vti_associateownergroup: 3
    • vti_associategroups: 5;4;3;6;7;8;9;10;11;14;15;17;18;28
    • __InheritsAlternateCssUrl: False
    • vti_approvallevels: Approved Rejected Pending\ Review
    • __InheritsMasterUrl: False

Fancy that, there are three properties which interest me most at this point (indicated in red).
I simply set these values to “True” (note, that is a string of “True” and not a 1 or C# true)

However, it did not pull the correct values to begin with. Therefore, it would appear that SharePoint uses these settings for when the parent’s master pages/css are changed, and not relying on these settings for everytime the site is accessed.

All in all, here is the final code I came up with for my Feature (inside FeatureActivated function):

SPWeb web = (SPWeb)properties.Feature.Parent;
Hashtable hash = web.AllProperties;
try {
web.MasterUrl = web.ParentWeb.MasterUrl;
hash["__InheritsMasterUrl"] = “True”;
web.Update();
}catch { }
try {
web.CustomMasterUrl = web.ParentWeb.CustomMasterUrl;
hash["__InheritsCustomMasterUrl"] = “True”;
web.Update();}catch { }
try {
web.AlternateCssUrl = web.ParentWeb.AlternateCssUrl;
hash["__InheritsAlternateCssUrl"] = “True”;
web.Update();
}catch { }

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.