Monday, July 18, 2011

Anonymous access to SharePoint application page

When create an application page and view it anonymous, the authentication will pop up.

By default, the application inherits from LayoutsPageBase. To make the anonymous access work, we need to inherits from UnsecuredLayoutsPageBase.



For more information, please refer to:




Beside changing the inherit class, we also need to override the AllowAnonymousAccess property like below:


        protected override bool AllowAnonymousAccess

        {

            get

            {

                return true;

            }

        }

Sunday, July 17, 2011

SharePoint 2010 CQWP date format

Sometimes we need to customize the style of SharePoint Content Query Web Part (CQWP). If we need to change the datetime column display format, here are general steps we can do:



1. Open your top-level site in Sharepoint Designer, click “All Files – Style Library – XSL Style Sheets – ItemStyle.xsl”
 

2. Please add following reference right below the “xmlns:cmswrt” (usually line 6)

xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"



3. Then we can add xsl variable to save the converted result like below

<xsl:variable name="Created"> <xsl:value-of select="ddwrt:FormatDateTime(string(@Created) ,1033 ,'dd.MM.yyyy')" /></xsl:variable>



Here is more information about  ddwrt:FormatDateTime:


List of supported locale identifiers in Word



Custom Date and Time Format Strings



SharePoint Data View Web Part Extension Functions in the ddwrt Namespace

Saturday, July 16, 2011

Post.aspx overflow in customized master page

We are using customized master page in our new SharePoint 2010 publishing website. After enabling the blog site template, we find the blog article display page: post.aspx has some display problem with our master page layout.



We're using fixed width in master page. However, the post.aspx always stretch over the fixed width and the horizontal scrollbar always shows up no matter how short the post content is.



After checking the page css heritance, we find the culprit is the empty comment style settings in the blog.css file.  We can find it in the following folder of 14 hive direcotry:

14\TEMPLATE\LAYOUTS\1033\STYLES



And here is the line we need to modify:

.ms-commentsempty

{

width:775px;

}



As we see, it has fixed width settings. We can change it to 100% if your customized master page mainContent div is small than this.

Wednesday, July 6, 2011

Enable Session state for SharePoint 2010

By default, the Session state is disable in SharePoint 2010. If we use Session in application page, following exception will occur:


To enable the Session status in SharePoint, we need to take following two steps:

1. Change the EnableSessionState to ture in the page declaration like below:
<%@ Page Language="C#" AutoEventWireup="true" EnableSessionState="True" ...

2. Modify the web.config file (C:\inetpub\wwwroot\wss\VirtualDirectories\80 by default), add this line:
<add name="Session" type="System.Web.SessionState.SessionStateModule" preCondition="" />
After
<remove name="Session" />




Monday, May 30, 2011

Inline script in SharePoint master page / page layout

When I'm testing some SharePoint menu customization with inline server scripts in the page layout. The test page applied this page layout cannot be visited because of following error message.

  Code blocks are not allowed in this file

After a quick search on the Internet, this error is due to the default security settings which disable the inline server scripts running in SharePoint. To turn it off, we have to change the PageParserPaths settings in web application's web.config file like below:

<PageParserPath VirtualPath="/yoursite/_catalogs/masterpage/*" CompilationMode="Always" AllowServerSideScript="true" />

As we know there are several web.config files in different locations for SharePoint . Here is official list of all web.config files:
http://msdn.microsoft.com/en-us/library/ms460914.aspx

What we need to modify is the content web application's config file in the following directory:
\\Inetpub\wwwroot\wss\VirtualDirectories\ Port_Number