Saturday, June 4, 2011

Sharepoint 2010 XSLTListViewWebPart using xsllink path.

In my last post i explained how to customize html for XSLTListViewWebPart. Click Here to read the post. In the current blog i will take the same example and show you how to use the same template for multiple XSLTListViewWebParts. Throughout the application.



  1. Create a list with name "Sample". Add the fields

    • Name

    • Address

    • Email

    • Picture



  2. Go back to screen and add some data.

  3. Adding the data will give you the default look. As I mentioned above that the default look is a XSLTListViewWebPart.

  4. I will propose below given template design for viewing.

  5. Create a file with title "Sample.xsl". Copy the content and paste it in file.

    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    exclude-result-prefixes="msxsl" xmlns:ddwrt2="urn:frontpage:internal">

    <xsl:output method='html' indent='yes'/>

    <xsl:template match='dsQueryResponse'>
    <table cellpadding="10" cellspacing="0" border="1" style="padding:25px;">
    <tr>
    <td colspan='2'>
    <b style="font-size:25px;">Friend's List</b>
    </td>
    </tr>
    <xsl:apply-templates select='Rows/Row'/>
    </table>
    </xsl:template>

    <xsl:template match='Row'>
    <tr>
    <td align="center">
    <img style="height:100px;border:5px solid #888;">
    <xsl:attribute name="src">
    <xsl:value-of select="@Picture"></xsl:value-of>
    </xsl:attribute>
    <xsl:attribute name="alt">
    <xsl:value-of select="@Title"></xsl:value-of>
    </xsl:attribute>
    </img>
    </td>
    <td valign="top">
    <b>Name : </b><xsl:value-of select="@Title"></xsl:value-of><br></br>
    <b>Email : </b><xsl:value-of select="@Email" disable-output-escaping="yes"></xsl:value-of><br></br>
    <b>Address :</b><br></br>
    <blockquote><xsl:value-of select="@Address" disable-output-escaping="yes"></xsl:value-of></blockquote>
    </td>
    </tr>
    </xsl:template>
    </xsl:stylesheet>


  6. Upload the XSL file on any of the "Document Library" or "Style Library" and copy the http path of that file. In my case it's "/Style%20Library/Sample.xsl".

  7. Open the current website in "Sharepoint Designer 2010".

  8. Goto "Links and Libraries".

  9. Find the list and click it. On the right hand side in the views you will find the default view with title "All Pages".

  10. Once you open the screen you will only see view on that screen with tag.
    <WebPartPages:XsltListViewWebPart></WebPartPages:XsltListViewWebPart>

  11. Split the screen and select the webpart from UI. Will automatically select the whole list view.

  12. On the top ribbon bar select "Design" and under the sub options, on right hand side click "Customize Entire View"

  13. Once you click it. A big bunch of XSLT is added to the html.
    <xsl><xsl:stylesheet></xsl:stylesheet></xsl>

  14. Select and remove the whole block of
    <xsl><xsl:stylesheet></xsl:stylesheet></xsl>

  15. Paste the below given path over there.
    <XslLink>/Style%20Library/Sample.xsl</XslLink>

Sharepoint 2010 Customizing XSLTListViewWebPart

In sharepoint 2010 each and every list is XSLTListViewWebPart. The blog will explain steps to modify and show the XSLListViewWebPart to Show in a custom design.



  1. Create a list with name "Sample". Add the fields

    • Name

    • Address

    • Email

    • Picture



  2. Go back to screen and add some data.

  3. Adding the data will give you the default look. As I mentioned above that the default look is a XSLTListViewWebPart.

  4. Open the current website in "Sharepoint Designer 2010".

  5. Goto "Links and Libraries".

  6. Find the list and click it. On the right hand side in the views you will find the default view with title "All Pages".

  7. Once you open the screen you will only see view on that screen with tag.
    <WebPartPages:XsltListViewWebPart></WebPartPages:XsltListViewWebPart>

  8. Split the screen and select the webpart from UI. Will automatically select the whole list view.

  9. On the top ribbon bar select "Design" and under the sub options, on right hand side click "Customize Entire View"

  10. Once you click it. A big bunch of XSLT is added to the html.
    <xsl><xsl:stylesheet></xsl:stylesheet></xsl>

  11. Select and remove the whole block of
    <xsl:stylesheet></xsl:stylesheet>

  12. In my case i have updated it with.

    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    exclude-result-prefixes="msxsl" xmlns:ddwrt2="urn:frontpage:internal">

    <xsl:output method='html' indent='yes'/>

    <xsl:template match='dsQueryResponse'>
    <table cellpadding="10" cellspacing="0" border="1" style="padding:25px;">
    <tr>
    <td colspan='2'>
    <b style="font-size:25px;">Friend's List</b>
    </td>
    </tr>
    <xsl:apply-templates select='Rows/Row'/>
    </table>
    </xsl:template>

    <xsl:template match='Row'>
    <tr>
    <td align="center">
    <img style="height:100px;border:5px solid #888;">
    <xsl:attribute name="src">
    <xsl:value-of select="@Picture"></xsl:value-of>
    </xsl:attribute>
    <xsl:attribute name="alt">
    <xsl:value-of select="@Title"></xsl:value-of>
    </xsl:attribute>
    </img>
    </td>
    <td valign="top">
    <b>Name : </b><xsl:value-of select="@Title"></xsl:value-of><br></br>
    <b>Email : </b><xsl:value-of select="@Email" disable-output-escaping="yes"></xsl:value-of><br></br>
    <b>Address :</b><br></br>
    <blockquote><xsl:value-of select="@Address" disable-output-escaping="yes"></xsl:value-of></blockquote>
    </td>
    </tr>
    </xsl:template>
    </xsl:stylesheet>


  13. The output is the screen is below given screen.


Click here to read my post for using the xsl stylesheet with xsllink.

Thursday, April 7, 2011

Change the path of TempDB in SQL Server 2005

Error : System databases master, model, msdb, and tempdb cannot be detached.
use master

go
Alter database tempdb modify file (name = tempdev, filename = 'D:\SQL Database 2005\tempdb.mdf')
go
Alter database tempdb modify file (name = templog, filename = 'D:\SQL Database 2005\templog.ldf')
go

Saturday, January 1, 2011

URL Rewrite Using ASP.net 3.5 or Over

The blog will explin how we can achieve url rewriting in ASP.net 3.5 or Over.

Step 1 : Create a helper class title "SiteRouteHandler.cs".


#region System
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.Routing;
using System.Web.Compilation;
#endregion

namespace UrlRewrite
{
/// <summary>
/// Handler for routing
/// </summary>
public class SiteRouteHandler : IRouteHandler
{
#region Properties

/// <summary>
/// Page Virtual Path
/// </summary>
public string PageVirtualPath { get; set; }

#endregion

#region Implements IRouteHandler

/// <summary>
/// Gets the handler in return
/// </summary>
/// <param name="requestContext"></param>
/// <returns></returns>
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
Page page = BuildManager.CreateInstanceFromVirtualPath(PageVirtualPath, typeof(Page)) as Page;
foreach (var item in requestContext.RouteData.Values)
{
HttpContext.Current.Items["qparam." + item.Key] = item.Value;
}
return page;
}

#endregion
}
}


Step 2 : In global.asax.cs file declare the routes you want to give to the pages with a particular pattern. Use the SiteRouteHandler.cs class for getting the params mentioned in the route pattern. The "{ID}", "{AspxPage}" and "{PageNumber}" are the dynamic values which can be used on our aspx page for manupulation. So if the link is "http://localhost/UrlReWrite/blog/123/This-is-a-blog.aspx/32". Than according to the pattern "123" is {ID}, "This-is-a-blog" is {AspxPage} and 32 is {PageNumber}. "~/Blog.aspx" is the actual page.


using System.Web.Routing;
protected void Application_Start(object sender, EventArgs e)
{
//Clears all route
RouteTable.Routes.Clear();
//Handles the route
RouteTable.Routes.Add("Blog", new Route("blog/{ID}/{AspxPage}.aspx/{PageNumber}", new SiteRouteHandler() { PageVirtualPath = "~/Blog.aspx" }));
}




Step 3 : Now on Blog.aspx we can use params to retrieve the data.


/// <summary>
/// The blog id from the query string
/// </summary>
private int BlogID
{
get
{
if (Context.Items["qparam.ID"] == null)
{
return 0;
}
return Convert.ToInt32(Context.Items["qparam.ID"]);
}
}

/// <summary>
/// The blog id from the query string
/// </summary>
private string AspxPage
{
get
{
if (Context.Items["qparam.AspxPage"] == null)
{
return string.Empty;
}
return Context.Items["qparam.AspxPage"].ToString();
}
}

/// <summary>
/// The Page Number
/// </summary>
private int PageNumber
{
get
{
if (Context.Items["qparam.PageNumber"] == null)
{
return 0;
}
return Convert.ToInt32(Context.Items["qparam.PageNumber"]);
}
}


Please let me know about your thoughts.

Thursday, November 18, 2010

Make MVC working with Virtual Directory

I have referred this site to get the MVC applicaiton working using Virtual directory. There is no direct way to get the MCV working on the IIS. It can run through port by default but making it work with IIS Virtual Directory follow this link.

http://haacked.com/archive/2008/11/26/asp.net-mvc-on-iis-6-walkthrough.aspx