Thursday, February 26, 2009

No searchresults for content available in welcome pages

I wrote a custom multilingual searchwebpart which uses the FullTextSqlQuery class to execute a search query. The webpart is used in a WCM scenario and his task was to find all publishing pages related with the given keyword.

After a while I noticed something weird... the webpart could find all keywords available in various fieldcontrols except for those content available in welcome pages.

After some research, it seems to be a SP bug. Thank goodness, MS has already released a hotfix package for this.

Monday, February 2, 2009

Peekaboo Bug: IE7

I ran across an ugly IE bug while developing a page layout. After some research it seems to be a crazy-making "peekaboo" IE bug.

Peekaboo (also spelled Peek-a-boo) is a game similar to hide and seek, but played with babies. In the game, one child, teenager, or adult hides their face, pops back into the baby's view, and says — to the baby's amusement Peekaboo! I see you!

Symtoms:
Certain content mysteriously disappears when you take some mouse action.

In my case it looks like this:










Cause
:
Setup of floating elements

Fix:
You have to set the "Layout" for the DIV element. You can set "Layout" in different manners eg. position, zoom, height,... attribute.

The hasLayout MS-property is a sort of flag: when it is set, the element has this layout “quality”, which includes special capabilities — for instance, on the floating and stacking — for the element itself and for its non-layouted child elements.

Some more information about hasLayout: The concept of hasLayout in IE/Win.

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: