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

Thursday, November 18, 2010

SharePoint wss_content log file keeps growing

The another day I received a request to check an issue with our production SharePoint Server 2010. The user could not save edited documents or upload documents to the library. Different error messages pop up. After further investigation, we found that the SharePoint database server is running out of disk space. The database file check showed that the largest data base is the wss_content (Of course, it's the SharePoint content DB).  Surprisingly, the log file wss_content.ldf had triple size of wss_content.mdf.

So we backed up the log file and then shrink the log file to get back lots of space. Then the problem was gone. Meanwhile, we limited the wss_content.ldf  to a fixed size to avoid this growth.

However, one month later, the problem reoccurs again. And if you check the serer log, you will find following error
 
Unknown SQL Exception 9002 occurred. Additional error information from SQL Server is included below.
The transaction log for database 'WSS_Content' is full. To find out why space in the log cannot be reused, see the log_reuse_wait_desc column in sys.databases
 

We have to repeat the log backup to get back space. At the same time, we do more check on the database recovery mode configuration and find it's "Full" mode, that means, the log file will keep growing and once it's up to the throttle, it  will require the log backup. This is mandatory task because the "Full Recovery Mode" means, you can recover your database to an arbitrary point in time, which is based on the transactions in the database log file.

So if you don't want this point-to-time recovery possibility (maybe you already has backup plane for your database), you can just switch back the content db recovery mode to "Simple".

More information about More information of SQL Server, you can find here:

Recovery Model Overview

Thursday, November 11, 2010

Create shortcut link for adding Alert in Sharepoint 2010

In out-of-box blog template of SharePoint 2010, if we want to set up alert for the blog, we have to go to all site content -> lists -> post and then use the Alert ribbon in the List tab. Or if you are blog contributor, you can click on the quick like "manage posts" to switch to the posts list and then do the Alert setting. Neither of these is straightforward enough.

If we want to add shortcut for adding Alert for this blog, how are we going to do this?

Actually, SharePoint 2010 has centralized Alert management feature and there is a subscription page for every site in the farm. The page path should be similar with this one:
http://woss01/blog/_layouts/SubNew.aspx

As we see, it's under site "_layouts" folder. And it does support the "List" QueryString parameter so that we can pass the List GUID to set up alert for specific list.

To check what's the GUID for your list, we can always go to the list settings page. Right click on "Title, description and navigation" and copy the URL. Paste that into notepad and copy everything after "List=" in the string. That's your URL Encoded GUID for the list.

Once we identify the list URL Encoded GUID, here is the quick link of adding alert for this list: