Monday, February 2, 2009

How To: Manipulate Navigation Settings Programmatically

__ Global navigation



__ Current navigation



Global navigation

1) web.Navigation.UseShared = true; web.Update();
2) web.Navigation.UseShared = false; web.Update();

Current navigation

1) publishingWeb.InheritCurrentNavigation = true;
publishingWeb.NavigationShowSiblings = false;
publishingWeb.Update();

2) publishingWeb.InheritCurrentNavigation = false;
publishingWeb.NavigationShowSiblings = true;
publishingWeb.Update();

3) publishingWeb.InheritCurrentNavigation = false;
publishingWeb.NavigationShowSiblings = false;
publishingWeb.Update();

Note: InheritCurrentNavigations value is "false" by default.

PS. Thanks to Robin's post for pointing me in the right direction and for his help ;)

Friday, January 2, 2009

How To: Alternative login mechanism for public MOSS Site

To start the new year I'll show you how to make an alternative login mechanism for your public SharePoint site. The solution consists of 2 parts:
  • Hide the "Sign in" link for anonymous users
  • Create a Login subsite with a redirect page.

The reason for hiding the "Sign in" link for anonymous users is obvious. If your site doesn't need a login system for anonymous users - it can be confused to show a "Sign in" link.

1) Hide the "Sign in" link
Place a SPSecurityTrimmedControl around the Welcome usercontrol within your masterpage.



The SPSecurityTrimmedControl is responsible for showing/hiding certain content, based on user rights. The Welcome usercontrol is responsible for showing the "Sign in/Welcome John Doe" link.

When you navigate to your site as an anonymous user, you'll notice that the "Sign in" link isn't visible anymore. Hmm... If we want to contribute to the site, we have to log in right? How can we login to the site if the link is not visible? Read on...


2) Create a Login subsite with a redirect page.

Create a subsite (based on the blank site template) on the toplevelsite and call it "Login". The next thing we have to do is to create a redirect page on the Login site. You can make one with the OOTB site template "Redirect Page". The "Redirect Page" page layout contains a redirect control for automatically directing readers to any specified URL.


Go into edit mode of our newly created redirect page and fill in the following URL in the Redirect URL textbox:




/_layouts/Authenticate.aspx?source=/pages/default.aspx


The authenticate page gives you the opportunity to log in to the site. The querystring source tells us where to go when the authentication process is finished.

The last thing we have to do is to set the Redirect Page as the welcome page of our "Login " site.

Conclusion
When we enter our sharepoint site as an anonymous user, we don't see a "Sign in" link anymore. If we want to contribute (read: log in) to the website - all we have to do is to navigate to http://localhost/Login.

Friday, December 26, 2008

Predefine styles in HTML editor in MOSS

A quick note about predefining custom styles in a HTML editor:
Standard, the HTML editor detects CSS classes whose names have the prefix .ms-rteCustom. You can easily extend the OOTB styles by adding .ms-rteCustom-XXX to your custom stylesheet. The name "XXX" will then become available in the styles dropdown within the HTML editor.

Another option is to specify a unique CSS class name prefix. This give you the ability to present different custom styles for different HTML editors of the publishing page. To make a unique CSS class, you have to assign a PrefixStyleSheet property to the HTML field control.

Example:
<.PublishingWebControls:RichHtmlField id="Content" FieldName="PublishingPageContent" runat="server" PrefixStyleSheet="myUniqueClass"./>
Afterwards you can define the "myUniqueClassCustom" class in you custom stylesheet.
Warning: you have to append the word "Custom" to the class, otherwise it won't work! In my opinion, MS doesn't explain this very well...

Example:

Syntax = .[PrefixStyleSheetPropertyName]Custom-[TitleAvailableInEditor]

.myUniqueClassCustom-Header1
{
font-weight: bold;
font-size: 16px;
}

Read How to: Customize Styles for more information.

Sunday, December 7, 2008

Bug: Publishing Image aka RichImageField

Problem:
In certain cases the RichImageField renders an HTML encoded image. It just renders image tags but doesn't render the image.

Workaround:
You have to build a webcontrol that inherits from RichImageField and decode the HTML.

Source: Publishing Images are shown in encoded Html/text instead of showing the image - temporary solution

Wednesday, November 26, 2008

Tip! Yet another CAML query tool

CAML (Collaborative Application Markup Language) is an XML based markup language used with the family of Microsoft SharePoint technologies (Windows Sharepoint Services and Office SharePoint Server). Unlike plain XML, CAML contains specific groups of tags to both define and display (render) data. [wikipedia]

With other words CAML defines various aspects in SharePoint like: views, fields, site definitions, ...

With CAML you can also define queries, which is useful to extract some data from SharePoint lists. Now... writing a simple CAML query isn't that difficult. Given the following example:





It can be difficult if you have more conditional clauses:







Now I probably hear you say: "Sven, what are you talking about? I use the CAML query builder from U2U to construct my queries. That's pretty easy!". I know... that tool is really helpful but what if you have to construct your query dynamically? You can build a flexible query class to simplify the process of creating queries, but it's not necessary. Carlos Segura Sanz (MVP) did this already with his "Yet another CAML Query tool (ala SQL).

With that tool you can construct your query ala SQL. Later on, you can transform the SQL syntax to CAML syntax. Example:
using IdeSeg.SharePoint.Caml.ParseQuery;

string query = @" WHERE ContentType='sharepoint'
AND Firstname = 'Sven'
AND Lastname = 'Gillis'
GROUPBY Title DESC
ORDERBY _Author"
;
try
{
string camlQuery = CAMLParser.Query(query);
SPList list = null;
SPQuery query = SPQuery();
query.Query = camlQuery;
SPItemCollection col = list.getitems(query);
}
catch (ParserException ex) {}
Quite easy, isn't it?

Use "=null" as CAML IsNull operator and "<>null" as IsNotNull also you can use dates enclosed into sharp characters #01/01/1990# the sql Like operator is replaced by CAML Contains and the at "@" operator for the CAML BeginsWith. Also support parentheses for operator precedence.

Oh... btw if you download YACAMLQT you can also use a windows application to support your development. It looks something like this:


















I recently used it in a project and it works like a charm!

Resources:

Saturday, November 22, 2008

WCM: Publishing Site Definition

Creating a new publishing website typically begins by creating a new publishing site collection based on your custom publishing site definition. Nevertheless, it is not necessary to create a custom one because you can also start with the OOTB Publishing Portal Site Definition and then remove the parts that are superfluous. It is quite obvious that this method is not ideal. Starting off with the Blank Site Definition and activating the publishing features is a better option because then you have a quite clean environment to start with.

Probably the best option is to create a Publishing Site Definition from scratch. This way, you "almost" have full control of the provisioning process. Below a few examples which elements you can specify:
  • The welcome page url and the appropriate (custom) pagelayout
  • Automatically activate masterpage, styles, ... features
  • Available web templates
  • Automatically activate the ViewFormPagesLockDown feature - A special feature that restrict access for anonymous users to published content only
  • Alternate CSS url
  • And so on...
In one of my next posts I'll show you how to set a welcome page with your own pagelayout with a custom content type (specified in your publishing site definition).

Saturday, November 8, 2008

Off-topic: E.T.A.

Marvin has the most boring job - ever. But all is not as it seems...