dinsdag 18 december 2012

SharePoint 2010: Hiding the Recently Modified on Team Sites

I was asked today about hiding the Recenlty Modified menu from the quicklaunch of SharePoint 2010 Team Sites.

image

SharePoint 2010: Expand the User Profile info by default

Out of the box, the SharePoint 2010 User Profile page uses a bit of JavaScript to truncate the user’s info like Email, School etc. with a “more information” hyperlink that can be clicked to show all the info.  The user’s description text is also similarly semi-hidden on page load.

The following quick CSS hack can make both these detail areas fully visible by default, and also hide the “more information” / “hide information” hyperlink”:

SharePoint 2010: minimal.master

When you create a custom minimal.master it’s also required to have all the placeholders defined. We already know this from the v4.master but why are they needed when they are not used? They are necessary for the edit mode of the minimal masterpage. When you edit a minimal masterpage and you have only defined the minimal.master placeholder you get error messages like “Cannot find ContentPlaceHolder ‘PlaceHolderLeftNavBar’ in the master page '~masterurl/default.master', verify content control's ContentPlaceHolderID attribute in the content page.”

List of all the required ContentPlaceHolders:

woensdag 5 december 2012

SharePoint list view group by content type

By default it’s not possible to group your list items by contenttype. After some research on internet I founded a solution on codeplex:

SharePoint 2010 ViewEdit Group By Content Type

Actually it’s nothing more than adding some javascript with a script link to each page.

vrijdag 16 november 2012

Images from picture library not displayed in IE

Today I discovered a strange behavior in Internet Explorer. I  uploaded some images to my image library and I referred to them in my custom aspx page. All the images displayed correctly except one. In Firefox everything rendered correctly, in IE only the thumbnail and the web image was available. The full image was not available and I received a red cross on my page.

Conclusion: the image was corrupt!

donderdag 15 november 2012

How to use SharePoint’s default modal popup from code behind?

A while ago I needed to create a shopping basket. When you click on an item in that basket it would be nice if that item opens in a modal popup. But how can you access the default SharePoint modal popup dialog if it isn’t in your masterpage?

I used following code:

public static class Helper
{
    public static string GetDialogURL(string url, bool refreshOnClose, double width, double height)
    {
        string str = string.Concat(new object[]
		{
            "SP.UI.ModalDialog.showModalDialog({ url:'",
			url,
			"',tite: 'Move Documents',allowMaximize: true ,showClose: true,width:",
			width,
			",height:",
			height
		});
        if (refreshOnClose)
        {
            str += ",dialogReturnValueCallback: function(dialogResult){SP.UI.ModalDialog.RefreshPage(dialogResult)}";
        }
        str += "});";
        return str;
    }
    public static string GetDialogURL(string url)
    {
        return Helper.GetDialogURL(url, true, 700.0, 800.0);
    }
}

maandag 12 november 2012

XSL template to obtain all visible fields in Content Query WebPart

When we are editing XSLT for Content Query WebPart, XSLTListViewWebPart or any other WebPart with configurable XSLT, you can obtain all list fields and their values with following template:
<xsl:template name="ShowXML" match="Row[@Style='ShowXML']" mode="itemstyle">
    <xsl:variable name="SafeLinkUrl">
      <xsl:call-template name="OuterTemplate.GetSafeLink">
        <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
      </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="DisplayTitle">
      <xsl:call-template name="OuterTemplate.GetTitle">
        <xsl:with-param name="Title" select="@Title"/>
        <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
      </xsl:call-template>
    </xsl:variable>
    <b>
      Item: <i>
        <a href="{$SafeLinkUrl}" title="{@LinkToolTip}">
          <xsl:value-of select="$DisplayTitle"/>
        </a>
      </i>:
    </b>
    <ol>
      <xsl:for-each select="@*">
        <xsl:sort select="name()"/>
        <li>
          <xsl:value-of select="name()" />
          <xsl:text disable-output-escaping="yes"> </xsl:text>
          <i>
            <xsl:value-of select="."/>
          </i>
        </li>
      </xsl:for-each>
    </ol>
    <br />
  </xsl:template>

Notice that @ is the beginning char of any list field.

woensdag 7 november 2012

SharePoint 2010 Search Center MasterPage with navigation

It’s hard to navigate from a Search Center, so I decided to modify the minimal masterpage to allow you to show the topnavigation of the page. It will also show the site icon and breadcrumb navigation just like the v4.master does.

Minimal masterpage with navigation

woensdag 31 oktober 2012

SharePoint 2010 Branding: what’s publishing masterpage all about

It’s a real disaster to start branding with the default v4.master. It’s much easier when everything is commented and outlined like it should be. That’s what I did today.

v4.master

Enjoy it!

Transparency settings for all browsers


Transparency css that covers all browsers.

Very handy css class

.transparent
{
/* Required for IE 5, 6, 7 */ /* ...or something to trigger hasLayout, like zoom: 1; */
width: 100%;

/* Theoretically for IE 8 & 9 (more valid) */ /* ...but not required as filter works too */ /* should come BEFORE filter */
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";

/* This works in IE 8 & 9 too */ /* ... but also 5, 6, 7 */
filter: alpha(opacity=50);

/* Older than Firefox 0.9 */
-moz-opacity:0.5; /* Safari 1.x (pre WebKit!) */
-khtml-opacity: 0.5;

/* Modern! /* Firefox 0.9+, Safari 2, Chrome any? /* Opera 9+, IE 9+ */
opacity: 0.5;
}

donderdag 25 oktober 2012

Set ribbon smaller via CSS

Thanks to my colleague (Laurent Schoenaers) for following css:

body #s4-ribbonrow {background-color: #FFA113; margin-top: -20px;}
.ms-siteactionsmenuinner {background:transparent;background-color:#FFA113;border-color:#FFA113;}
.ms-cui-topBar2 {border-bottom:0px;}
.ms-cui-TabRowRight {margin-top: -12px !important; padding-top: 36px !important;}
.ms-cui-ribbonTopBars div {border-bottom:1px solid transparent;}
.s4-trc-container-menu {margin:0;} 



before:


before_ribbon


after:


after_ribbon

woensdag 24 oktober 2012

SharePoint 2010 template for Photoshop

Did they ever asked you to create a SharePoint design? A design in the sense of a webdesign. Then I have a nice solution!
You can download below the default SharePoint 2010 team site design in photoshop format. Every part is created in a layer.
SharePoint 2010 design assets

RichHtmlField for custom field not rendering HTML

I had multiple RichHtmlFields on my page, and one was displaying correctly while another was not.  When I viewed the fields via the powershell, I noticed a difference in the SchemaXML, the WORKING field had the following additional properties:

     RichText="True"
     RichTextMode="FullHtml"

I found a script to update the problem field, and the problem went away for me (look below for script). The change has to be made at the list level for it to take affect on existing pages/lists, but I believe making the modification to the column at the root web (or correct subweb) would work as well.     
     $web = $site.OpenWeb($site.RootWeb.ID)
     $list = $web.Lists["Pages"]
     [Microsoft.SharePoint.Publishing.Fields.HtmlField]$field =   [Microsoft.SharePoint.Publishing.Fields.HtmlField]$list.Fields.GetFieldByInternalName("PageContentFld")
     $field.RichText = $true
     $field.RichTextMode = [Microsoft.SharePoint.SPRichTextMode]::FullHtml
     $field.Update()
     $list.Update()

You may want to check your field to make sure those properties are set.


donderdag 6 september 2012

Trigger resize event with jQuery cross-browser

Bind an event handler to the "resize" JavaScript event, or trigger that event on an element

jQuery has a built-in method for this:

$(window).resize(function () { /* do something */ }); 

For the sake of UI responsiveness, you might consider using a setTimeout to call your code only after some number of milliseconds, as shown in the following example, inspired by this:

function doSomething() { 
alert("I'm done resizing for the moment");
};

var resizeTimer;
$(window).resize(function() {
clearTimeout(resizeTimer);
resizeTimer = setTimeout(doSomething, 100);
});

vrijdag 24 augustus 2012

SharePoint 2010: custom markup styles

How to complete customize the SharePoint 2010 markup styles

 
First of all you need to specify all your styles
  • Font colors
  • Fonts
  • Font Sizes
  • Mark colors
  • Predefined Styles
  • Predefined Markup Styles
  •  
The second step: write a css with all your specified styles
I have written a complete customized markup css file. You can download it at the end of this blog post. The location of the css file doesn't matter. I put always it in de layouts folder of the SharePoint root.

maandag 20 augustus 2012

Calculate total size of SPWeb object

 

private static long GetWebSize(SPWeb web)
{
Log(
String.Format("===> Calculate the total subsite size of {0}.", web.Title));
long totalWebSize = 0;
try
{
foreach (SPFolder folder in web.Folders)
{
totalWebSize += GetFolderSize(folder);
}
foreach (SPWeb subweb in web.Webs)
{
totalWebSize += GetWebSize(subweb);
subweb.Dispose();
}
}
catch (Exception ex)
{
Log(
string.Format("===> ERROR while calculating the total web size. Error: {0}, StackTrace: {1}", ex.Message, ex.StackTrace));
}
Log(
string.Format("===> Total size of subsite {0} is: {1}", web.Title, totalWebSize.ToString()));
return totalWebSize;
}

vrijdag 10 augustus 2012

SP2010: Set rigths of custom action

Set the rights of a custom action

You can set the rights on a custom action with the property "Rights". You can see an example below.

<CustomAction
Id="{0C1B0CCF-DCF6-4FCB-85E0-2CE401C17085}"Location="Microsoft.SharePoint.StandardMenu"GroupId="SiteActions"Title="Nieuwe pagina"Description="Maak een pagina aan in de bedrijfsstijl"ImageUrl="_layouts/1043/styles/img/logo_klein.png"Rights="AddAndCustomizePages"RequireSiteAdministrator="FALSE"><
UrlAction Url="~site/_Layouts/CreatePage.aspx"/></
CustomAction>

This property is needed if you want to set minimal rights to execute your custom action.
A nice list of the available rights for custom actions:

donderdag 9 augustus 2012

Add jQuery library to a webpart via code

How to load your jQuery library at the same time as your webpart?

Add the jQuery library reference via code to your webpart.

protected override void Render(HtmlTextWriter writer)
{
 writer.AddAttribute(HtmlTextWriterAttribute.Src, "/_layouts/1043/STYLES/myUZA/js/jquery-1.4.2.min.js");
 writer.AddAttribute(HtmlTextWriterAttribute.Type, "text/javascript");
 writer.RenderBeginTag(HtmlTextWriterTag.Script);
 writer.RenderEndTag();
}

Another option is to do it in a full javascript block. You write the javascript code, put it in a string and register the javascript block via C# code:

//Load the jQuery library if it's not yet loaded
string js = @"<script type=""text/javascript"">
<">if (typeof jQuery == 'undefined') {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = '/_layouts/1043/STYLES/myUZA/js/jquery-1.4.2.min.js';
document.getElementsByTagName('head')[0].appendChild(script);
}
</script>"
;

/// Register the javascript block
if
(!Page.ClientScript.IsClientScriptBlockRegistered(jsKey))
{
this.Page.ClientScript.RegisterClientScriptBlock(GetType(), "jQueryLib", js, false);
}

 

woensdag 8 augustus 2012

SharePoint 2010: Document Library - Group By expand on item click

Expand group by clicking on the item


To expand for example group Categorie by clicking on Aankoop. We need to write a jQuery function and call that jQuery function in a Content Editor webpart on the page where the ListViewWebpart is located.

vrijdag 6 juli 2012

SP2010 Sequential Workflow Send Email

Send Email in a sequential workflow


Create a Send Email task activity on your workflow.

Don't forget to set the CorrelationToken to the same token as your workflow! See earlier post. 

The code behind of that task is:

SPUser siteOwner = IntranetUtility.GetSPUser(currentItem, IntranetFieldId.SiteRequest.SiteOwner);
SPUser siteBackupOwner = IntranetUtility.GetSPUser(currentItem, IntranetFieldId.SiteRequest.SiteBackupOwner);

SendEmail confirmationMail = (SendEmail)sender;
confirmationMail.To = siteOwner.Email + ";" + siteBackupOwner.Email;
confirmationMail.Subject = string.Format("Your site {0} is created", currentItem.Title);
confirmationMail.Body = "Link to created site";
 
SPUtility.SendEmail(workflowProperties.Web, true, false, confirmationMail.To, confirmationMail.Subject, confirmationMail.Body);

SP2010: Sequential Workflow Correlation Token SendEmail

Workflow Foundation Correlation Token error

Within a workflow that I was developing, there was a requirement to notify a group of SharePoint users that a lookup service had failed. This particular activity was within a parallel activity sequence. I chose to use the SendEmail activity to notify the users, but incorrectly set the Correlation Token to a new value. When testing this functionality in the workflow I received an error:

SharePoint LOG
  1. WinWF Internal Error, terminating workflow Id#
  2. System.InvalidOperationException: Correlation value has not been initialized on declaration emailToken_JobNumberCreate for activity sendEmail_JobNumberNotCreated. at System.Workflow.Activities.CorrelationService.InvalidateCorrelationToken

The correct Correlation Token for a SendMail Activity is the “Workflow” token. The reason, which is fairly obvious, is that the SendEmail activity maps to the workflow, not to a task, which would require a Task Token

vrijdag 22 juni 2012

SharePoint 2010: Manage navigation programmatically C#

How to set navigation options programmatically?

  • Don't inherit global navigation
  • Don't include pages in global navigation
  • Include subsites in quicklaunch
  • Set ordering
  • Set navigation items of the topnavigation manually via xml
  • Add parent site to the quicklaunch if it exist

donderdag 14 juni 2012

SharePoint 2010: Create a custom wiki page

How to create a custom wiki page in SharePoint 2010 with a simple FeatureReceiver?


With this code it's pretty easy:

private string wikiFullContent = string.Empty;

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
using (SPWeb web = properties.Feature.Parent as SPWeb)
{
//* Define page payout
wikiFullContent = FormatBasicWikiLayout();
//* Add page to library
SPList sitePages = web.Lists.TryGetList("$Resources:core,WikiLibDefaultTitle;");
if (sitePages == null)
{
sitePages = web.Lists.EnsureSitePagesLibrary();
}


woensdag 13 juni 2012

SharePoint 2010: Restrict web templates

Define which web templates may be available when you create a subsite


In the analysis of a new project was described that the users only a few webtemplates could see when they want to create a new subsite. After some research on the internet I found that it is possible to define that via the UI of SharePoint 2010:

Site Actions -> Site Settings -> Page layouts and site templates

(default)

(after the selection)



In this settings page you can define which web templates you set available but that's not a solution on the question of the analysis. You can't ask to each contributor to set this setting by themself so I wrote a featureReceiver and via featureStapling I hang to the defined site templates.
Important! If you want to do this via code be sure that the Publishing Infrastructure and Publshing Feature is activated!

dinsdag 12 juni 2012

SharePoint 2010: Starter v4.master without tables

Starter v4.master with div tags instead of table tags

Standard is the default masterpage of SharePoint (v4.master) build on tables. Every designer knows that tables only bring troubles so I desided to convert all the tables to div tags.

Via the link below you can download the result.


Enjoy it!

SharePoint 2010: Show the parent site in the breadcrumb

How to show the parent site in the breadcrumb of your custom masterpage?

By default there is a masterpage that has this configuration. You can find this in the default nightandday.master.

What needs to be done to have this in your custom masterpage?

Add following code to in the <div class="s4-ca"> tag:

<!-- Breadcrumb with parent site -->
<div class="breadcrumb">
  <asp:SiteMapPath
   runat="server"
   SiteMapProviders="SPSiteMapProvider,SPXmlContentMapProvider"
   RenderCurrentNodeAsLink="false"
   NodeStyle-CssClass="breadcrumbNode"
   CurrentNodeStyle-CssClass="breadcrumbCurrentNode"
   RootNodeStyle-CssClass="breadcrumbRootNode"
   HideInteriorRootNodes="true"
   SkipLinkText="" />
</div>

The css here defined contains the default style of the v4.master headbreadcrumb.

maandag 11 juni 2012

SharePoint 2010: Custom Site Definition

Failed to instantiate file "default.master" from module "DefaultMasterPage"


Today I got this error while trying to create a new Site Definition in SharePoint 2010. It turns out that the TemplateName you select in your webtemp_custom.xml file:

<Template Name="CustonSiteDefinitions" ID="10000">

Must match the folder in your SiteTemplates directory:

14/TEMPLATE/SiteTemplates/CustomSiteDefinitions