Display a image thumbnail in DVWP

Here is the code to insert to the div or td(Need to change the SiteName, PictureLibraryName):

 

<img src="{concat('/SiteName/PictureLibraryName/_t/', substring-before(@NameOrTitle, concat('.',@FileType)), '_', @FileType, '.', @FileType)}" />

The src string would look something like this:

/SiteName/PictureLibraryName/_t/testPic_gif.gif

@NameOrTitle should have a value as testPic.gif

 

Reference:

How to get a thumbnail view of an Image:

http://www.sharepointkings.com/2008/06/how-to-get-thumbnail-view-of-image.html

Advertisements

Display special character in SharePoint global navigation, quick launch and breadcrumb

On my SharePoint global navigation menu, quick launch or breadcrumb, for pages that has special character in their name, the characters are encoded. For example, “Health & Safety” displays as “Health &amp; Safety”, “Tomorrow’s Leader” displays as “Tomorrow#39;s”.

The solution for the global navigation is to add

EncodeTitle=”false” in the AspMenu control.

<!-- ------------| TOP NAVIGATION  |------------ -->
<div>
<!-- top navigation publishing data source -->
<SharePoint:AspMenu
   ID="TopNavigationMenuV4"
   Runat="server"
   EnableViewState="false"
   DataSourceID="topSiteMap"
   AccessKey="<%$Resources:wss,navigation_accesskey%>"
   UseSimpleRendering="true"
   UseSeparateCss="false"
   Orientation="Horizontal"
   StaticDisplayLevels="1"
   MaximumDynamicDisplayLevels="1"
   SkipLinkText=""
   EncodeTitle="false"
   CssClass="s4-tn"/>

<asp:SiteMapDataSource
   ShowStartingNode="False"
   SiteMapProvider="CombinedNavSiteMapProvider"
   id="topSiteMap"
   runat="server"/>
</div>
<!-- ------------| TOP NAVIGATION  |------------ -->
The solution for the quick launch is to add EncodeTitle=”false” in the quick launch control:
<SharePointWebControls:AspMenu id="V4QuickLaunchMenu" runat="server" EnableViewState="false" DataSourceId="QuickLaunchSiteMap" UseSimpleRendering="true" EncodeTitle="false" UseSeparateCss="false" Orientation="Vertical" StaticDisplayLevels="10" MaximumDynamicDisplayLevels="7" SkipLinkText="" CssClass="s4-ql noindex" />
The solution for the breadcrumb is different. We need to add javascript to do this. Here is the js code:
<script type="text/javascript">

    jQuery(document).ready(function () {

        fixSiteTitleBug();

    });

    function fixSiteTitleBug()
    {
        var searchAmp = '&amp;';
        var replaceAmp = '&';
        var searchQuote = '#39;';
        var replaceQuote = '\'';

        // Fix Quick Launch items
        var html = jQuery('#s4-leftpanel-content').html().replace(searchPattern, replacement);
        jQuery('#s4-leftpanel-content').html(html);

        // Fix breadcrumb items
        jQuery('a.SolidBreadCrumbRoot').each(function () {
            jQuery(this).html(jQuery(this).html().replace(searchAmp , replaceAmp ));
        });

        jQuery('a.SolidBreadCrumb').each(function () {
            jQuery(this).html(jQuery(this).html().replace(searchAmp , replaceAmp ));
        });

        jQuery('.SolidBreadCrumbCurrent').each(function () {
            jQuery(this).html(jQuery(this).html().replace(searchAmp , replaceAmp ));
        });

        jQuery('a.SolidBreadCrumbRoot').each(function () {
            jQuery(this).html(jQuery(this).html().replace(searchQuote, replaceQuote));
        });

        jQuery('a.SolidBreadCrumb').each(function () {
            jQuery(this).html(jQuery(this).html().replace(searchQuote, replaceQuote));
        });

        jQuery('.SolidBreadCrumbCurrent').each(function () {
            jQuery(this).html(jQuery(this).html().replace(searchQuote, replaceQuote));
        });
    }

</script>
Reference:

Add a printer friendly button to SharePoint publishing page

One of the request from my client is to allow user to print a page with only text content on it. This feature is quite common in many websites.

After reading Kathy Hughes “Microsoft SharePoint Designer 2010 Unleashed”, it’s pretty easy to do so in SharePoint 2010.

Scenario: I have 3 custom page layout for my site, home page layout, landing page layout and detail page layout. I only want to have a print button on pages that uses content page layout.

Here are the steps:

1. Create a new CSS file in the site collection’s Style Library and name it print.css. In this file, you can try hide all the components that you don’t want to see in the print view.

2. Open detail page layout. Add the following html inside the PlaceHolderMain tag.

< a id=”printer” onclick=”myPrinter(‘printer’)” href=”#” target=”_blank”><img src=”/Style Library/images/printer.png”></a>

3. On the same page, scroll to the top. Find the closing tag of PlaceHolderAdditionalPageHead. If you don’t have this tag, you need to add it first. Add the following JavaScript immediate before the closing tag. Of course you can add these code to a js file and add the link here instead.

<script type=”text/javascript”>
//if the url doesn’t contain printfriendly, use the normal style sheet
if (location.search.indexOf(‘printfriendly’) == -1){
document.write(‘<link rel=”stylesheet” type=”text/css” href=”/Style Library/css/gw_content_style.css”/>’);
}
//otherwise use the print style sheet and open the print window
else
{
document.write(‘<link rel=”stylesheet” type=”text/css” href=”/Style Library/css/gw_print.css”/>’);
window.print();
}

function myPrinter(id)
{
//if url doesn’t contain a question mark
if(location.search.indexOf(‘?’) ==-1)
{
var qrystr = document.getElementById(id).href;
//if  the url doesn’t contain a hash
if (qrystr.indexOf(‘#’) == -1)
{
//use the existing url.
//This means the button has been pressed before
//so the printfriendly parameter is already added.
document.getElementById(id).href = qrystr;
}
//otherwise the button hasn’t been pressed before
//so remove the # and add the printfriendly parameter
else
{
var newstr = qrystr.replace(‘#’, ‘?printfriendly=true’);
document.getElementById(id).href = newstr;
}
}
//this is used for pages like DisplayFullStory?ID=3 which has a parameter
else
{
var qrystr = document.getElementById(id).href;
if (qrystr.indexOf(‘#’) == -1)
{
document.getElementById(id).href = qrystr;
}
else
{
var newstr = qrystr.replace(‘#’, ‘&printfriendly=true’);
document.getElementById(id).href = newstr;
}
}
}
</script>

4. That’s it. When you test it, make sure you go to a page that uses the detail page layout.

 

Reference:

http://www.codingforums.com/archive/index.php/t-80517.html

SharePoint 2010 Blog Site Branding

After creating DVWPs for the last 3 days, I’m glad to move on to something new. That is creating a master page for a blog site in SharePoint 2010.

The first issue I faced was to change the master page. From the Site Settings, there is no option for Master Page. After reading this article, I enabled the publishing feature and now I see the master page option. Changed the system master page to be the custom one that I created. This potentially will be inconvient for site admins, but after reading a few articles online, there is no workaround for this. MS didn’t have a solution for this either.

SharePoint blogs are considered to be a collabration feature. Therefore, it can’t do a lot of things that publishing pages can do. For example, it uses the System Master Page instead of Site Master Page. It doesn’t have the option for choosing a different page layout.

In order to customize the master page of my blog, I had to change the System Master Page to my custom master page. The backend now looks a little funny because I have a copyright footer added to the master page. All the forms also display the footers.

Here are the steps I took to add a custom master page:

1. Open the root site in SharePoint Designer, navigate to Master Page. Duplicate the v4.master and name it blog-v4.master

2. Navigate to Style Library, create a new css file and call it blog-v4.css

3. In blog-v4.master, attach the following link just before </head>

<SharePoint:CssRegistration name=”/Style Library/blog-v4.css” After=”corev4.css” runat=”server”/>

4. Add the footer div after DeveloperDashboard

<SharePoint:DeveloperDashboard runat="server"/>
</div>
<div class="bFooter">
    <p>Copyright © 1992 - 2010 My Limited - All Rights Reserved | <a target="_blank" href="/sitemap.aspx">Sitemap</a></p>
</div>

5. Go back to blog-v4.css, add all the styles to customize the master page.

6. Check in both blog-v4.master and blog-v4.css

7. Go back to the browser and open the blog site, go to Site Actions -> Site Settings -> Under Look and Feel -> Master page -> change System Master Page to blog-v4.master
Reference:

http://www.paulgrimley.com/2011/02/changing-master-page-for-sharepoint.html

Wiki Pages Master Page and Hide Recently Modified panel on the left side

The normal wiki pages from a wiki page library on a publishing site uses System Master Page rather than Site Master Page.

To hide the Recently Modified panel on the left side, add the following css script.

<style type=”text/css”>
.s4-recentchanges { display: none; }
</style>

See Randy’s post for more detail.

 

A note to myself:

Site Master pages  only change the master page for publishing pages.  Whereas the System Master Page covers all forms and view pages.

Site Master page  styles everything in the Pages library. System master  page basically gets everything else in SharePoint 2010

Display the home link in top navigation menu in SharePoint 2010

On my SharePoint 2010 site, I needed to display a home link in the top navigation menu. One way of doing it is to add a heading called “Home” in the navigation list(Site Actions->Site Settings->Look and Feel->Navigation->Navigation Editing and Sorting). After adding this, all the back end pages have a top navigation menu with two Home links. So  I needed to do it in a way that works for both front end and back end.

1. Open the master page in SharePoint Designer 2010.

2. Search for “topSiteMap”. 5 lines after that, change the value of StaticDisplayLevels to 2.  3 lines after that, you should see a tag called asp:SiteMapDataSource. Change the value of ShowStartingNode to True.

Here is all the code for the navigation menu in the master page:

<div id=”s4-topheader2″ style=”border:0;background:transparent;”>
<a name=”startNavigation”></a>
<asp:ContentPlaceHolder id=”PlaceHolderTopNavBar” runat=”server”>
<asp:ContentPlaceHolder id=”PlaceHolderHorizontalNav” runat=”server”>
<SharePoint:AspMenu
ID=”TopNavigationMenuV4″
Runat=”server”
EnableViewState=”false”
DataSourceID=”topSiteMap”
AccessKey=”<%$Resources:wss,navigation_accesskey%>”
UseSimpleRendering=”true”
UseSeparateCss=”false”
Orientation=”Horizontal”
StaticDisplayLevels=”2″
MaximumDynamicDisplayLevels=”3″
SkipLinkText=””
CssClass=”s4-tn noindex”/>
<asp:SiteMapDataSource ShowStartingNode=”True” SiteMapProvider=”CombinedNavSiteMapProvider” id=”topSiteMap” runat=”server”/>
</asp:ContentPlaceHolder>
</asp:ContentPlaceHolder>
</div>

Top Navigation Customization

Here are some classes that used to style the top navigation. This code are used for one color navigation menu.

.s4-tn{ background-color:#8dc63f; padding:0px; margin:0px!important; width:960px!important; }

/* Global navigation */

.s4-tn li.static > .menu-item{ color:#fff; white-space:nowrap; border:1px solid transparent; padding:10px 15px; line-height:12px; height:15px; font-size:12px; font-weight:bold; }

/* Hover */

.s4-tn li.static > a:hover{ background:url(“/_layouts/Images/selbg.png”) repeat-x left top; color:#000; text-decoration:none; }

/* Selected */

.s4-tn a.selected { background:url(“/_layouts/images/selbg.png”) repeat-x left top; background-color:#8dc63f; color:black!important; text-decoration:none; border:1px transparent solid; padding-right:10px; padding-left:10px; margin:0px; }

/* Selected hover*/

.s4-tn .selected > a:hover{ color:black!important; }

/* Sub items border */

.s4-tn ul.dynamic{background-color:#C8F38C; }

/* Menu Item */

.s4-tn li.dynamic > .menu-item{display:block; padding:4px 10px; background-color:#fff; color:#000; border-bottom:1px solid #ccc;} .s4-tn li.dynamic > a, .s4-tn li.dynamic > a:visited {color:#000;}

/* Menu Item Hover Over */

.s4-tn li.dynamic > a:hover{color:#000; text-decoration:none; background:url(“/_layouts/Images/selbg.png”) repeat-x left top; background-color:#C8F38C; font-weight:bold;}

/*Remove the down arrow next to first level menu items*/

.menu-horizontal A.dynamic-children SPAN.additional-background {  background-image:none!important;  padding-right:0px!important; }