Category: CodeProject

Powershell to create calendar in SharePoint with categorized overlays

Creating calendars in SharePoint 2010, changing default categories and then creating view and overlay for each category can take a lot of clicks. To save time and effort I created a powershell script which can be used as follows

& ‘.\Calendar Overlay.ps1’ -webUrl {SITEURL} -listName “{LISTNAME}” -categories “{CommaSeparatedCategories}”

It takes three command line parameters which are

-webUrl – The site url where you want to create the calendar

-listName – The name of calendar list

-categories – Comma separated values for categories

For example if you would like to create a calendar named Yearly events on http://myspsite/marketing with road show, marketing boot camp 1 and digital campaign 1. You can pass in the following arguments

& ‘.\Calendar Overlay.ps1’ -webUrl http://myspsite/marketing -listName “Yearly Events” -categories “Road show, Marketing Boot camp 1, Digital Campaign 1”

The resulting calendar would look like

Calendar overlays created with Powershell

Source for the script is as follows:

###############################################################################
# Creating Calendar overlays in SharePoint 2010 using Powershell
# Version          : 1.0
# Url              : https://khurrampunjwani.wordpress.com
# Creator          : Khurram Punjwani, http://twitter.com/khurrampunjwani
###############################################################################

param (
    [string]$webUrl = $(throw "-webUrl is required."),
	[string]$listName = $(throw "-listName is required."),
    [string]$categories = $(throw "-categories is required.")
 )

[array]$categoriesArray = $categories -split ","

Function Get-SPCalendarWeb(){

	#Clear screen first
	Clear-Host
	
	#Load web where Calendar is supposed to be created
	$web = Get-SPWeb -Identity $webUrl
	Write-Host "SP Web Loaded " $web.Title
	
	#Create new calendar
	New-SPCalendar

	$web.Dispose()
}

Function Add-TestEntries($cal){
	$listItem = $cal.AddItem()
	$listItem["Title"] = "Test 1"
	$listItem["Category"] = $categoriesArray[0]
	$listItem["EventDate"] = [System.DateTime]::Now
	$listItem["EndDate"] = [System.DateTime]::Now.AddHours(4)
	$listItem.Update()
	
	$listItem = $cal.AddItem()
	$listItem["Title"] = "Test 2"
	$listItem["Category"] = $categoriesArray[1]
	$listItem["EventDate"] = [System.DateTime]::Now
	$listItem["EndDate"] = [System.DateTime]::Now.AddHours(4)
	$listItem.Update()
}

Function New-SPCalendar(){
	$web.Lists.Add($listName,"",[Microsoft.SharePoint.SPListTemplateType]::Events)
	$cal = $web.Lists.TryGetList($listName);
	
	Write-Host "Calendar created"
	
	#Delete default categories and add the ones specified in command line
	Add-CalendarCategories $cal
	
	#Add Views with Filters
	Add-SPCalendarViews $cal

	#Add test entries
	Add-TestEntries $cal
}

Function Add-SPCalendarViews($cal){
	$view = $cal.Views["Calendar"]
	$viewFields = $view.ViewFields.ToStringCollection()
	$viewData = ""
    $viewData += ""
    $viewData += ""
    $viewData += ""
    $viewData += ""
	#XML for calendar overlays
	$calendarSettings = "  "
	#To show different color for category views
	$colorIndex = 1 
	
	#Create views for categories so there will be one view for each category
	foreach($category in $categoriesArray){
		#Create filter for the view to show events from the respective category
		$viewQuery = ""
		$viewQuery += ""	
		$viewQuery += ""
		$viewQuery += ""
		$viewQuery += ""
		$viewQuery += ""
		$viewQuery += ""
		$viewQuery += ""
		$viewQuery += ""
		$viewQuery += ""
		$viewQuery += %{"{0}" -f $category}
		$viewQuery += ""
		$viewQuery += ""
		$viewQuery += ""
		
		$newView = $cal.Views.Add($category,$viewFields,$viewQuery,3,$false,
			$false,"CALENDAR",$false)
		$newView.ViewData = $viewData
		$newView.Update()

		%{"View created for {0} category" -f $category} | Write-Host
		
		#Update XML for Calendar Overlay, each view would be added as an overlay
		$calendarSettings += %{"  " -f $category}
		$calendarSettings += %{"

How to create multilingual user experience in SharePoint 2010

This post describes how we can create multilingual user experience in SharePoint 2010. Let’s say we’ve a site named “HR” and under that site we’ve a document library called “Leave Requests”.

Let’s assume we’ve both English and Arabic users we’ve been asked to give them interface in their respective languages, creating variations for site and creating two separate lists is an option but then we’ll have to manage two lists and deal with them separately and most importantly variation only works with Publishing sites. Now there is another option and a better one for this type of scenarios which is Multi-lingual user interface (MUI).

MUI simply allows us to select a display language so after we configure it, users can just simply change their display language and all out-of-the-box stuff will be displayed in the respective language and we can also very easily translate custom columns, menus and stuff. From a developer’s point of view it is same as localizing content in Asp .NET using resource files but this time we don’t have to create them (More benefits of multilingual user interface).

Okay enough talking let’s see this in action.

Step 1: Download and install the desired language pack

Step 2: Rerun the SharePoint Product and Technologies configuration wizard

Step 3: Now let’s go to HR site settings

Step 4: Let’s go in to Language settings under Site Administration

SharePoint 2010 Site Administration

Step 5: Select Arabic and click ok

SharePoint 2010 Language Settings

Step 6: Now we should be able to see Select Display Language in User Settings menu.

SharePoint 2010 Display Language

Step 7: Let’s go to Leave Request library in our HR site and select Arabic and see what happens

SharePoint 2010 Arabic MUI View

Step 8: Okay now we can the interface is in Arabic, let’s relax for a while but wait the list title “Leave Requests” is still in English as well the title of default view “All Documents”, we can easily change them. Let’s go to Library setting and then General settings and replace the English title with its Arabic counterpart.

SharePoint 2010 Editing List name MUI

Step 9: Now we can see the list name is appearing in Arabic and we’ll go in English we can see it’s the English one because SharePoint keep them in resource files, we can also change view name, menus, quick launch and custom column names like this as well. (More details on what’s supported and what’s not on)

Step 10: Now changing titles and other stuff might be cumbersome if we keep going in to settings just to change title and to avoid this we can export translation which will give us the resource file, we can very easily edit it using Visual Studio or any other xml editor and translate our content and then upload it again by importing translations. Let’s go to Site settings and then Language settings to export translation.

SharePoint 2010 Site Administration Export Translations

Step 11: Let’s select Arabic and export, afterwards we’ll get a prompt to save resource file for our site, we can then edit it and upload it back.

SharePoint 2010 Exporting Translation for MUI

That’s all for now my friends, thanks for reading. I hope you find this post useful.

10 easy steps to create an elegant jQuery slide show in SharePoint 2007 using Content Query Web Part

Recently I’d a requirement to create a slideshow in SharePoint 2007 and content query web part is great for these types of scenarios where a list has to be query and list items are to be rendered with some HTML. There are a lot of great jQuery plugins available for slideshow, we’ll be using jQuery.Popeye. You can use the following steps to use any other plugin if you like, okay so let’s get started.

  1. Download jQuery and jQuery.Popeye plugin
  2. Go to Style Library, open with explorer and paste jQuery.Popeye folder from the downloaded archive along with jquery-1.8.1.min.js
  3. Create a Picture Library and upload images that you’d like to be displayed in Slide Show.
  4. We’ve to create a new XSL template which will generated the necessary HTML for slide show so open the site in SharePoint Designer and then navigate to All Files, Style Library, XSL Style Sheets, make copy of ItemStyle.xsl and then edit ItemStyle.xsl
  5. Go to bottom of the file and paste the following XSL before </xsl:stylesheet>

    <xsl:template name="PopeyeSlideShow" match="Row[@Style='PopeyeSlideShow']" mode="itemstyle">
    <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>

    <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="Header">
    <xsl:if test="count(preceding-sibling::*)=0">
    <![CDATA[
    <div id="ppy1">
    <ul>
    ]]>
    </xsl:if>
    </xsl:variable>

    <xsl:variable name="Footer">
    <xsl:if test="count(following-sibling::*)=0">
    <![CDATA[
    </ul>
    <div>
    <div>
    <!--<div>
    <strong></strong>
    </div>-->
    </div>
    <div>
    <a title="Previous image">Previous Image</a>
    <a title="Enlarge">Enlarge</a>
    <a title="Close">Close</a>
    <a title="Next image">Next Image</a>
    </div>
    </div>
    </div>
    ]]>
    </xsl:if>
    </xsl:variable>

    <xsl:value-of select="$Header" disable-output-escaping="yes" />
    <li>
    <a>
    <xsl:attribute name="href">
    <xsl:value-of select="$SafeLinkUrl"></xsl:value-of>
    </xsl:attribute>
    <img>
    <xsl:attribute name="src">
    <xsl:value-of select="$SafeLinkUrl"></xsl:value-of>
    </xsl:attribute>
    </img>
    </a>
    </li>
    <xsl:value-of select="$Footer" disable-output-escaping="yes" />
    </xsl:template>

  6. Create a new page, drop content query web part, edit web part, collapse query section, select show items from following list and select the library you created in Step 4, also select picture library as List Type.
  7. Collapse presentation section and select PopeyeSlideShow as ItemStyle so that the HTML we wrote while creating XSL template in step 5 is applied while rendering images returned.
  8. Now all that’s missing is to include CSS for this plugin along with including references to JavaScripts and then finally calling the plugin so let’s add this now.
  9. Now again open SharePoint Designer, go to All Files, Style library and create a new js file, name it jquery.popeye.loader.js, edit it and paste the following

    <link type="text/css" rel="stylesheet" href="/Style%20Library/jQuery.popeye/css/popeye/jquery.popeye.css" media="screen" >
    <link type="text/css" rel="stylesheet" href="/Style%20Library/jQuery.popeye/css/popeye/jquery.popeye.style.css" media="screen" >
    <script src="/Style%20Library/jquery-1.7.2.min.js"></script>
    <script src="/Style%20Library/jQuery.popeye/lib/popeye/jquery.popeye-2.1.min.js"></script>
    <script type="text/javascript">
    <!--
    $(function(){
    $("#ppy1").popeye({
    autoslide:true
    });
    });
    //-->
    </script>
  10. Now edit the page which we created in step 6 and drop content editor web part so we can include jquery.popeye.loader.js. Modify the shared web part and enter /Style%20Library/jquery.popeye.loader.js in the content link box, test the link and then click ok

Now you should have something like the following image.

Creating a jquery slideshow in SharePoint_2007 using Content Query Web Part

Hope you find this post useful, thanks for reading.

How to use Hyper-V or VMWare virtual machines on Windows 7 (32 or 64 bit) without converting them

Installing Windows Server 2008 as a dual boot so you can play some VHDs might not be very tempting and productive. Following are some good products which you can install on Windows 7 (32 or 64 bit).

I’ll be covering VirtualBox in this post. I like three things about it which are

  • It’s free
  • It can run 64 bit Virtual machines on 32 bit host OS.
  • It doesn’t require conversion. For example you’ve a Hyper-V VHD, what you can do is start Virtual Box, do some clicks and voila you can use it without converting it into another format.

Now you might come across some intriguing error messages while trying to configure and start a Hyper-V VHD on VirtualBox so let’s go through the process one time.

  1. Start VirtualBox and create a new Virtual Machine, type name, select OS and select memory you would like to allocate to this virtual machine on next screen.
  2. Now unselect Start-up disk, click next, you’ll get a warning to attaching or creating hard disk, we’ll configure it in a while so click continue to finish.

  3. Select the VM, click settings and then go to Storage.

  4. Now click add attachment and then add hard disk (First icon in at the bottom).
  5. Choose existing hard disk and browse VHD. You should’ve something similar to the following screen.

  6. Click ok and try starting the VM. Now you should’ve Windows 2008 64 bit up and running on your 32 bit OS.

I hope you found this post useful, please like the post and do follow me on twitter.

Thanks for reading.

How to approve or reject SharePoint workflow using Nintex workflow

To approve or reject a SharePoint Workflow from a Nintex Workflow is very easy. There is a web service exposed from SharePoint which is Workflow.asmx, you can access it at

http:// server /_vti_bin/workflow.asmx

Now the method that we will be using to action our SharePoint workflow is AlterToDo. This method takes the following arguments:

  • Item (The URL location of an item on which a workflow is being run)
  • todoId (Unique identifier of the assigned task)
  • todoListId (Globally unique identifier (GUID) of the assigned task list containing the task)
  • taskData (Task data for conversion into a hash table)

Okay so back to Nintex now.

Step 1: Add a call web service workflow action and configure it.

Step 3: Add URL of workflow.asmx web service in the URL field, specify username and password and click refresh to update list of available methods in the Web Service

Step 3: Select SOAP Editor in editor mode, this is necessary as you will be adding some xml in TaskData parameter and select SOAP builder mode seems to html encode < > signs which results in error

Step 4: Specify item, todoId, todoListId and paste the following xml in tag.

<my:myFields xmlns:my=”http://schemas.microsoft.com/office/infopath/2003/myXSD&#8221; >

<my:TaskStatus>Approved</my:TaskStatus>

<my:Status>Completed</my:Status>

<my:PercentComplete>1.00000000000000</my:PercentComplete>

<my:Completed>1</my:Completed>

</my:myFields>

Your configuration should look something like this

Calling Workflow.asmx using Nintex workflows

Try some fixed values first for testing purposes and click run and then replace them.

I hope you find this post useful. Thanks for reading.

How to set view level permissions out of the box in SharePoint 2010

Today I’d a requirement to set permissions on list view, I remembered this feature was present in SharePoint 2007 but I couldn’t find it in SharePoint 2010. After doing a bit of research, I found out a way to do this out of the box.

I’ll be using the default Task list for illustrative purposes. However this method can be used on any list or document library.

Let’s say for example we want to create a view in task list to show users the tasks which are assigned to them and their manager should be able to view all tasks. So users should only be able to access my tasks view and only their managers can access all tasks view.

Step 1: Create a document library. I’m naming it Restricted views. It is better to not show this library in quick launch because it’ll be used to host the all tasks view.

Creating restricted views document library

 

Step 2: Now open SharePoint Designer 2010, go to All Files – Lists – Tasks and copy AllItems.aspx (This is All Items view)

Default views in SharePoint 2010 task list

 

Step 3: Go to All Files – Restricted Views (It is the document library which we created in step 1) and paste the AllItems.aspx there

Paste AllItems.aspx in Restricted views document library

 

Step 4: Go to All Files – Lists – Tasks and delete AllItems.aspx

Step 5: Open the SharePoint 2010 portal – Site Actions – View All Site Content – Restricted Views, you will see AllItems.aspx there.

Change item permissions in SharePoint 2010 Document Library

 

Step 6: Select AllItems.aspx – Document Permissions – Stop Inheriting Permissions and then grant permissions to manager.

Step 7: Go back to SharePoint Designer 2010, go to All Files – Lists – Tasks and then delete AllItems.aspx

Step 8: Go to All Files – Restricted Views, copy AllItems.aspx and paste it to All Files – Lists – Tasks.

Step 9: Open the SharePoint 2010 portal, go to Task List, when you click the views drop down, you’ll see two views titled All Items, don’t worry.

Changing list view in SharePoint 2010

 

Step 10: Go to list settings – views and click All Tasks views, now you’ve to be careful here and delete the old view

Deleting list view in SharePoint 2010

 

Make sure URL of the view says /Lists/Tasks/AllItems.aspx and not /Restricted Views/AllItems.aspx, this is important because the view in Restricted Views library is the one with proper permissions.

Step 11: Now trying accessing the view as manager, you’ll be to see it and when you’ll try to access the view using any user who you didn’t give, they’ll see access is denied when they’ll try to access it.

Access denied on SharePoint 2010 List view

 

I hope this will help you out. Thanks.