Wednesday, August 08, 2007

How to put a latest post of your blog on sharepoint homepage

Recently, we had a requirement to create a blog site and also put a latest blog entry on the homepage of the

sharepoint site. To make things difficult, customer wanted only the preview of the latest post i.e. first few lines

and an out of the box solution :)

I was stuck with an awesome idea to accomplish this with DataForm webpart in MOSS 2007 and bingo, it worked ! Here is how to do it :

Open the page on which you want to place the blog entry in Sharepoint Designer. If its a publishing page, SPD wont allow you to directly open it, but instead it will open the page layout instead. To circumvent this, create a webpart page through sharepoint and open it in sharepoint Designer.

Once the page is open in sharpoint designer, Go to Insert -> Data View. It will open a data sources pane to select the data source. However our data source is a seperate blog site. Thus, Choose Connect to another library, Enter a display name and enter the URL of the blog site.

Now you will get the lists of all lists and libraries from the blog site. Choose the list Posts as it is the list in which blog posts are contained by default.

Once you have inserted the dataview, now we have to customize the XSLT of the DataForm webpart to make it show us only a preview of single post.

For this,

* Strip of the headers of the list, called Title, Body etc. enclosed inside the <th> tags, we dont want to show the headers obviously.

* Now to show the preview, we will make use of the function

<xsl:value-of select="substring-before(@Body,'<p')" disable-output-escaping="yes"/>

What this function does is, gives us all of the string upto the string <p. Now since @Body is in actual an HTML representation of the body post,

we will get the first paragraph of the blog in the result. disable-output-escaping="yes" will make sure that it does not renders the HTML as it is.

* You can also sort it by Modified to show the latest entry automatically.

For those, who does not want to make these modifications themselves, I am giving the snippet of the XSL which I used here :


<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal">
<xsl:output method="html" indent="no"/>
<xsl:decimal-format NaN=""/>
<xsl:param name="dvt_apos">'</xsl:param>
<xsl:variable name="dvt_1_automode">0</xsl:variable>
<xsl:template match="/" xmlns:x="
http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:SharePoint="Microsoft.SharePoint.WebControls">
<xsl:call-template name="dvt_1"/>
</xsl:template>

<xsl:template name="dvt_1">
<xsl:variable name="dvt_StyleName">Table</xsl:variable>
<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row"/><table border="0" width="100%" cellpadding="2" cellspacing="0">
<tr valign="top">
<xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">
<th class="ms-vh" width="1%" nowrap="nowrap"></th>
</xsl:if></tr>
<xsl:call-template name="dvt_1.body">
<xsl:with-param name="Rows" select="$Rows"/>
</xsl:call-template>
</table>
</xsl:template>
<xsl:template name="dvt_1.body">
<xsl:param name="Rows"/>
<xsl:for-each select="$Rows">
<xsl:call-template name="dvt_1.rowview"/>
</xsl:for-each>
</xsl:template>
<xsl:template name="dvt_1.rowview">
<tr>
<td class="ms-vb">
Posted : <xsl:value-of select="ddwrt:FormatDate(string(@Created),1033,3)"></xsl:value-of> by <xsl:value-of select="@Editor" disable-output-escaping="yes" />
<p/>
<b><xsl:value-of select="@Title"></xsl:value-of></b><p/>
<xsl:value-of select="substring-before(@Body,'<p')" disable-output-escaping="yes"/>
<p/>
</td><td class="ms-vb">
</td><xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">
<td class="ms-vb" width="1%" nowrap="nowrap">
<span ddwrt:amkeyfield="ID" ddwrt:amkeyvalue="ddwrt:EscapeDelims(string(@ID))" ddwrt:ammode="view"></span>
</td>
</xsl:if>
</tr>
<tr>
<td><a class="ms-vb" href="
http://sp.sony.com/sel/CorporateMarketing/multichannel/blog">Read More</a></td>
</tr>
</xsl:template></xsl:stylesheet>

Wednesday, July 11, 2007

SharePoint 2007: using ASP.NET server side code in your pages

This is fairly undocumented piece of information which I have got from this blog

http://www.bluedoglimited.com/SharePointThoughts/ViewPost.aspx?ID=242

I havn't tried it myself, so I cannot gaurantee its completeness. I am posting it

here for the sake of interest and community .....

In the web.config file in the Sharepoint virtual directory contains the following section:

<Sharepoint>
<SafeMode MaxControls="200" CallStack="false" DirectFileDependencies="10" TotalFileDependencies="50" AllowPageLevelTrace="false">
<PageParserPaths>
</PageParserPaths>
</SafeMode>
:
</Sharepoint>

By default the node <PageParserPaths> is empty. You can add <PageParserPath> nodes to specify the

virtual paths where you want to allow server side scripts:

<PageParserPaths>
<PageParserPath VirtualPath="/pages/*" CompilationMode="Always" AllowServerSideScript="true" IncludeSubFolders="true"/>
</PageParserPaths>

Where CompilationMode is one of the following values:

Always

The page should always be compiled (default value)

Auto

ASP.NET will not compile the page, if possible.

Never

The page or control should never be dynamically compiled.

I assume that the AllowServerSideScript and IncludeSubFolders flags speak for themselves.

Be careful with the virtual paths you specify in your PageParserPaths. Anyone that can modify or add a page to the virtual path can insert code that will be executed server side with no restrictions.

A good location to specify as a PageParserPath is the location where you store your masterpages, for example /_catalogs/masterpage. You can now add server side script to your masterpages, which makes it available in all pages using this masterpage.

<PageParserPaths>
<PageParserPath VirtualPath="/_layouts/masterpage/*" CompilationMode="Always" AllowServerSideScript="true" IncludeSubFolders="true"/>
</PageParserPaths>

Preventing caching of page : Strategies in ASP.NET 2.0 and MOSS 2007

Here I would discuss strategies to disable caching in your pages especially related to ASP.net and MOSS 2007.

If you wanted to prevent caching in plain old HTML, you would use these directives

<meta http-equiv="Expires" content="0">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">

I wont explain these tags here. You can refer to W3C HTML specification. Rather I would focus on how

to insert these HTML tags while developing in ASP.NET and MOSS 2007 i.e. master - content pages.

1) If you using plain aspx pages you can directly put these tags under the

<head> section and you are done.

If you are using master - content pages, you can add this to master page but beware, this will prevent

caching of all the pages.


Usually you are looking to prevent the caching of single page which contains dynamic data.

In that case, you can use strategies given below.


If you are using MOSS 2007, and want to prevent the caching of a content page, there are two choices:

  • Create a new page layout which contains these tags and bind that page to this page layout.
    This way you can, create more pages which do not get cached using this layout.

  • Entirely detach the page from its layout using Sharepoint Designer. This way, the markup is copied to the
    aspx page itself and you can add these tags easily. However this is not a recommended procedure as this
    is not scalable.

2) Add a contentplaceholder inside the <head> in your master page. Then in
any pages that need these headers, populate the content control with
these meta tags. Other pages don't need to populate (or even have) the
content control.

I do this a lot and it's much easier

If you want to do this programmatically, you can put this line in a webpart or custom control :

Page.Master.FindControl("Content PlaceHolder").InnerHtml = < no caching tags >

3)

This is a small piece of code, which programmatically adds the <meta http-equiv="refresh" ... />

to the <head> page.

void DisableBrowserCaching(HtmlHead hdr)
{
Control ctrl = (Control)hdr;

string currGMT =
DateTime.Now.ToUniversalTime().ToLongDateString() +
" " + DateTime.Now.ToUniversalTime().ToLongTimeString() + "
GMT";

HtmlMeta meta = new HtmlMeta();
meta.Name = "expires";
meta.Content = currGMT;
ctrl.Controls.Add(meta);

meta = new HtmlMeta();
meta.HttpEquiv = "pragma";
meta.Content = "no-cache";
ctrl.Controls.Add(meta);

meta = new HtmlMeta();
meta.HttpEquiv = "cache-control";
meta.Content = "no-cache";
ctrl.Controls.Add(meta);

}

You can use this code like this, in your controls or webparts

HtmlHead hdr = Master.Page.Header;
util.DisableBrowserCaching(hdr);

or if you are not using master pages, you can directly pass the Page.Header.

This works and, I think, is more general for the different browser
behaviors. Also, it allows me to set the behavior for any page, whether a
master page is involved or not.

Friday, May 18, 2007

Resolving Workflow Status Stopped when sending mail to a Sharepoint Group

There is a mysterious stalemate occurs when you create a normal sharepoint Designer workflow with An action of sending a mail to a sharepoint group. The workflow runs fine when run under Administrator Account but shows status stopped when run under any other account like Contributor etc.


This occurs due to the fact that by default, the visibility of members of sharepoint group is granted only To the members of those group. Any other user outside that group cannot enumerate the members of the group And hence the workflow fails with the status as stopped. To resolve the issue, Go to Sharepoint Group settings And allow Everyone to see the members of group.


This issue engrossed my whole day due to the fact that, there is no error reported when this occurs.

Monday, May 14, 2007

Data View Web Part Problems

Unable to display this Web Part. To troubleshoot the problem, open this Web page in a Windows SharePoint Services-compatible HTML editor such as Microsoft Office SharePoint Designer. If the problem persists, contact your Web server administrator.

This problem occurs if the site is saved as the template and restored onto another server.
The resolution is given here, I wont repeat to avoid unnecessary redundancy
http://suguk.org/forums/thread/3001.aspx

But in brief, therotically solution is

we have to add curly braces to the list ID

We have to do this before saving the site as site template. There are some five occurences of the site ID which we need to change, we just have to add curly braces to the listID then only designer generates the new list IDs for these webparts.






Thursday, February 22, 2007

EMC's Getting Out of the Way of the SharePoint Train
EMC Documentum and Microsoft today announced an alliance that integrates SharePoint 2007 with EMC's Documentum products. Some of the high points are:
    • Users will be able to use the Office 2007 and SharePoint 2007 user interfaces as ways to put content into the Documentum repository. All of a sudden, users -- especially casual users -- won't have to go to Documentum training to use the Documentum system.

Read the full story at
http://creese.typepad.com/pattern_finder/2006/10/emcs_getting_ou.html

Wednesday, February 21, 2007

Features of Office 14

Have a look at the Features that are being considered for Office 14….

Feature set includes:

· Better support on web 2.0

· Deeper unification of communications

· Knowledge networks (out of spps 2007)

· Content tagging/rating

· Improved search relevance and result refinement

· Enhanced WCM capabilities

· BI capabilities to business processes


Read here for more :

http://www.aeroxp.org/index.php?categoryid=10&p2_articleid=42