Friday, February 17, 2012

Sharepoint 2010 - Advanced Settings for Document library in SharePoint 2010 using PowerShell

In this article we will be seeing how to change the Advanced Settings for Document library in SharePoint 2010 using PowerShell and c#.

Go to Document Library => Library Settings => General Settings =>Advanced Settings.


Using C#:
using (SPSite site = new SPSite("http://serverName:1111/"))
                using (SPWeb web = site.RootWeb)
                    SPList docLibrary=web.Lists["Doc Library"];

                    // Change the advanced settings
                    // Update the changes

Using PowerShell
$site=Get-SPSite "http://serverName:1111/"
$docLibrary =$web.Lists["Doc Library"]
# Change the advanced settings
Content Types:


docLibrary.ContentTypesEnabled = false;

$docLibrary.ContentTypesEnabled = $false

Opening Documents in the Browser:DocShare3.gif

// Open in the client applicationdocLibrary.DefaultItemOpen = DefaultItemOpen.PreferClient;
// Open in the browserdocLibrary.DefaultItemOpen = DefaultItemOpen.Browser;
// Use the server defaultdocLibrary.DefaultItemOpenUseListSetting = false;


#Open in the client application
$docLibrary.DefaultItemOpen = "PreferClient"

#Open in the browser
$docLibrary.DefaultItemOpen = "Browser"

#Use the server default
$docLibrary.DefaultItemOpenUseListSetting = $false
Custom Send To Destination: 


docLibrary.SendToLocationName = "Shared Documents";
docLibrary.SendToLocationUrl = "http://serverName:1111/Shared%20Documents/";


$docLibrary.SendToLocationName = "Shared Documents";
$docLibrary.SendToLocationUrl = "http://serverName:1111/Shared%20Documents/";


docLibrary.EnableFolderCreation = false;

$docLibrary.EnableFolderCreation = $false



docLibrary.NoCrawl = true;

$docLibrary.NoCrawl = $true

Offline Client Availability:DocShare7.gif

C#:docLibrary.ExcludeFromOfflineClient = true;


$docLibrary.ExcludeFromOfflineClient = $true

Site Assets Library: 


docLibrary.IsSiteAssetsLibrary = false;

$docLibrary.IsSiteAssetsLibrary = $false



docLibrary.DisableGridEditing = true;


$docLibrary.DisableGridEditing = $true



docLibrary.NavigateForFormsPages = true;


$docLibrary.NavigateForFormsPages = $true

Sharepoint 2010 - Filter Web Part with QueryString: an issue?

In Sharepoint 2010, when you want to filter a List Web Part with a Form Web Part, you find the simple way with querystring and XSLT query.

List web part shows 5 results per page, and we have 3 pages (so 15 items).
I search for title and I see 3 results in the first page, but I see link for the other 3 pages.
And navigating the other page, I see one more result in second page and the third is empty...!
Filter shows results for the page 1 (3 items), for the page 2 (1 item) and for the page 3 (0 items), but divided in 3 pages.

It seems filter "hides" results not matching from view, keeping pages.

I decided to use filter with querystring used by Sharepoint when you filter columns.

So the address bar shows this:

You can use javascript to retrieve value for FilterFieldN (the column name to filter, internal name!) and FilterValueN (value to use in filter).

In this way, List Web Part filtered is in the right view: if I filter my 15 items, I found olny 3, but in one page.

Thursday, February 2, 2012

Sharepoint 2010 - Associate Workflow to List with Power Shell

I create a new Workflow Template (globally reusable) in root site and I associate it to a List in a Site Template.
But I need to update each sub site (created from my Site Template) with the new Workflow.

I use PowerShell, to cycle each subsite and associate WF to content type list.
This is command I used:

$site=Get-SPSite "http://sharepoint_root_site"

foreach($web in $site.AllWebs){
   $taskList=$web.Lists["Workflow Tasks"]
   $historyList=$web.Lists["Workflow History"]
   $culture=New-Object System.Globalization.CultureInfo("en-US")
   $wfTemplate=$web.WorkflowTemplates.GetTemplateByName("wfTemplate", $culture)
   $associationWF=[Microsoft.SharePoint.Workflow.SPWorkflowAssociation]::CreateListContentTypeAssociation($wfTemplate, "MyWFInSubSite", $taskList,$historyList)

It helps me for massive update.

Sharepoint 2010 - Filter List/Library Web Part with XSLT and Content Editor WP

I created a simple Filter Web Part with a Content Editor WP and simple XLST to filter List/Library with the LIKE feature.
It works for lists and libraries (in libraries not for Name field).

Create a page with Library Web Part to filter. Then add a Content Editor Web Part end edit HTML Source.
In HMTL, add an input textbox and two buttons, for reset filter and for submit filter.
Add some script as shown below:

<script type="text/javascript">

//this script get query string from URL
function querySt(ji){
  hu =;
  gy = hu.split("&");
  for (i=0;i<gy.length;i++){
    ft = gy[i].split("=");
    if (ft[0] == ji){
      return ft[1];

//this script set value read from query string in input field
function setValues(){
   if(querySt('qtitle') != null && querySt('qtitle') != "")
     document.getElementById('query_title').value = querySt('qtitle');

//this script reload page without filter in query string
function resetFilters(){
   document.location = "/SitePages/Search Documents.aspx";

//this script set query string and load page with filters
function getValues(){
   var el_query_title = document.getElementById('query_title');
   var value_query_title = el_query_title.value;
   window.location.href = "/SitePages/Search Documents.aspx?qtitle=" + value_query_title;

//this set values from query string after page is loaded (you can use your preferred method to do the same)


Title: <input name="query_title" id="query_title" type="text"/>
<input id="btn_reset" onclick="javascript:resetFilters();" type="button" value="Reset"/>
<input id="btn_filter" onclick="javascript:getValues();" type="button" value="Search"/>

Now, open Sharepoint Designer 2010 and edit page with filter.
Note: Edit page in Advanced Mode!

Click on List Web Part and in Ribbon Customizations, click on Customize XSLT (entire view).

In Ribbon Options, take care that column you want to filter is in view.
Now, Click on Parameter and add this parameters:

"qTitle", type Query String, with query string name qtitle (same as in the javascript above).
"lower", "upper" type None with value = "abcdefghijklmnopqrstuvwxyz" and "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

Last two parameters are for tranform to Lower or to Upper text to filter: if I search for "None", I found in text contains "None", "NONE", "none".
We see how to later.

Now, in the code of library web part, search for tag :

<xsl:param name="AllRows" select="/dsQueryResponse/Rows/Row[($EntityName = '' or (position() &gt;= $FirstRow and position() &lt;= $LastRow))]"/>

and substitute with this:

<xsl:param name="AllRows" select="/dsQueryResponse/Rows/Row[((@Title != $qTitle and $qTitle = '*') or (contains(translate(@Title,$lower,$upper),translate($qTitle,$lower,$upper)) and $qTitle != '*')) and ($EntityName = '' or (position() &gt;= $FirstRow and position() &lt;= $LastRow))]"/>

Note the change we made.
The select take all rows with Title different from qTitle, if qTitle is wild card, or rows which Title contains qTitle, if qTitle is a word. This do the LIKE filter for text.
We add the translate function, to check only upper text of Title and upper text of qTitle.

Save your page (if asked for update display, say No: some time this overwrites your changes)

Now, go to browser on your search page, and try to filter web part.
Note for address, with query string and the result in web part.

You can add other filter with other column: columns must be displayed in view.

For the date, you have to convert them for correct XSL query.