Friday, December 21, 2012

SharePoint 2010 - Recursive Query in List/Library


CAML query is by default non recursive. If you execute a CAML query, you will end up with items from the list root folder.

You have to define extra query options as shown below in case you want to query all folders and sub folders within a list (Recursive Query) :

query.ViewAttributes = "Scope='Recursive'";



From:
http://blogs.technet.com/b/meacoex/archive/2010/10/24/recursive-and-folder-scoped-linq-queries-in-sharepoint-2010.aspx

Wednesday, October 31, 2012

Sharepoint 2010 - The Text property is read-only and cannot be set

In a site, logged in with Admin, edit with Sharepoint Designer.
Copy default master page to create a new one.
Chech out new master page and edit some rows.
Then, save and set as Default Master Page for site.

Open browser, navigate to site and all it's ok! Fine!

Now, I log with another user and.... ERROR!

"The Text property is read-only and cannot be set"

In Sharepoint Log, you find somethings like below:

System.Web.HttpException: The 'Text' property is read-only and cannot be set.    at System.Web.UI.ControlBuilder.AddProperty(String filter, String name, String value, Boolean mainDirectiveMode)     at System.Web.UI.ControlBuilder.PreprocessAttributes(ParsedAttributeCollection attribs)     at System.Web.UI.ControlBuilder.Init(TemplateParser parser, ControlBuilder parentBuilder, Type type, String tagName, String id, IDictionary attribs) ....

Resolution!
Go to Sharepoint Designer and check in your new master page!!
Then, retry with other users, and you'll se it's allrights!

Remember that all you editi in masterpage will see by other users only if you check in masterpage.
In this case, other user cannot enable to view new object (masterpage) and then it get error on page.

Friday, October 5, 2012

Sharepoint 2010 - About Uselessness of Content Query Web Part?

.. Why Content Query Web Part...??

I did not found any reason to use Content Query Web Part..
Or maybe, I am no really skilled to find a way to use it with a real reduction of configuring costs.

In the same time I build custom XLS for CCQWP, I can develop a Custom web part with Visual Studio...
No, I think I develop custom wp in less time...
Sure, with minor performance, but it works anywhere and it has simple governance, for me...

And you? You found way to use "simple" CQPW?

Maybe, only a demoralization time..


Tuesday, September 25, 2012

Sharepoint 2007 - Modal Dialog Sharepoint2010-Like

Or .. How to show modal dialog with page content only.

In Sharepoint 2007 we don't have a client script framework that shows modal dialogs with ligthbox effect, as in Sharepoint 2010.
We can reproduce with a lot of jquery ui and similia.

In MOSS, we can use the function javascript of core.js, commonShowModalDialog.
Open Site and in Homepage, add a Content Editor Web Part with this simple code:


<a href="javascript:openInModalDialog()">CLICK HERE</a>

<script type="text/javascript">
function openInModalDialog()
{
  var url = "/Lists/Calendar/Calendar.aspx";
  commonShowModalDialog(url,"resizable: no; status:no; scroll: no; help: no; center: yes; dialogwidth:800px; dialogHeight:500px;",RetrieveItemValue);
}
</script>


Click on link opens modal dialog, but we show the entire page in window:



Now, open Calendar page in edit mode. Add Content Editor Web Part at the bottom of the page with code below.

We add jquery:

<script type="text/javascript" src="/intranet/Media/js/jquery-1.8.0.min.js"></script>

We define a new jquery function to get querystring values from url:

///////////////////////////////////////////////////////////
//FUNCTION GET QUERYSTRING VALUES
///////////////////////////////////////////////////////////
(function($) {
    $.QueryString = (function(a) {
        if (a == "") return {};
        var b = {};
        for (var i = 0; i < a.length; ++i)
        {
            var p=a[i].split('=');
            if (p.length != 2) continue;
            b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
        }
        return b;
    })(window.location.search.substr(1).split('&'))
})(jQuery);
///////////////////////////////////////////////////////////

Now, we add the function to retrieve page in modal dialog environment:

$(document).ready(function(){

 var isDlg = $.QueryString["isDlg"];
 if(isDlg && isDlg == "1"){
  $('body > :not(#MSO_ContentTable)').hide(); //hide all nodes directly under the body
  $("#MSO_ContentTable").appendTo('body');
 }

});

This function hides all elements in page, but the content table.

Then, save and back to home.
Edit first Content Editor WP, adding querystring "isDlg=1" to url in javascript:

var url = "/Lists/Calendar/Calendar.aspx?isDlg=1";


Now, save and click on Click Here link. Et voilĂ !


(
Note: An issue is that if you click on a link in modal dialog (i.e. New or change month) browser opens new windows page...
I think you can use jquery to control events on this modal dialog..
I did not try this solution.. 
)

Thursday, September 20, 2012

Sharepoint 2010 - Customizing Quick Launch with pages

How to show different quick launch menu items in different pages?

The quick launch in Sharepoint is an object common to all pages of the site.
To show menu items according to the page you visited, I followed client side method with javascript (jquery).
Here's how, using Sharepoint Designer 2010.

On css stylesheet of the site, I added this instruction, which hides all the items in the Quick Launch:

. s4-ql ul.root> li {
display: none;
}

Then, make note of the position of the menu items in the quick lanuch: eg.


0 - Document Libraries
1 - Lists
2 - MyLink
     0 - MySubLink1
     1 - MySubLink2
3 - MyOtherLink
4 - MyLastLink



The pages follows the following rules:

Page1 shows 0,1,4
Page2 shows 0,2,3
Page3 shows 0,2 (and sub ​​links 1), 3.4


And now, I change the master.page, adding references to jquery and inserting the following code:

//get all items in the quick launch
var li_nav = $(".vertical-menu>ul>li");
//get page name (from url, return page1.aspx)
var page_name = GetCurrentPageName();
//for each li
var i = 0;
li_nav.each(function(){
    if (page_name.indexOf("page1")> -1) {
       if (i == 2 || i == 3)
         $(this).hide();
       else
         $(this).show();
    }
    else if(page_name.indexOf("page2")> -1) {
       if (i == 1 || i == 4)
         $(this).hide();
       else
         $(this).show();
    }
    else if(page_name.indexOf("page3")> -1) {
       if (i == 1)
         $(this).hide();
       else if (i == 2) {
         $(this).show();
         var j = 0;
         $(this).children("ul").children("li").each(function(){
            if (j == 0){
                $(this).hide();
            }
            j++;
         });
       }
       else
         $(this).show();
    }
    else {
       $(this).show();
    }
    i++;
});

So, navigating to page1.aspx we see


0 - Document Libraries
2 - MyLink
     0 - MySubLink1
     1 - MySubLink2
4 - MyLastLink


To page2.aspx:

0 - Document Libraries
2 - MyLink
     0 - MySubLink1
     1 - MySubLink2
3 - MyOtherLink

To page3.aspx:


0 - Document Libraries
2 - MyLink
     1 - MySubLink2
3 - MyOtherLink
4 - MyLastLink

Wednesday, September 19, 2012

Resizing Cross-Domain IFrame with Javascript

I tried to find a way to pass height of page loaded in an IFRAME to parent document in order to reset the height of the IFRAME with javascript.
It's a simple coding, but .. if you use IFRAME with a page in a different domain, you cannot access to properties of page opened in IFRAME and from page to opener.

The idea is to be able to pass the value of the height of the content at regular intervals, using a javascript function, and try to read it by the parent.

This applies to the height value, but works for any data, of small size, to be passed client side from content of the iframe to container in a cross domain situation.
Obviously, if we can access page open iframe in edit.

NOTE: Both domains must be added to Trusted Sites.

Let's see how.
I put the following function in the page that I want to load iframe:

setInterval (function () {this.frames.status = getHeight();}, 400);

getHeight function () {

     var height;
    [we calculate body height, or div container height, if it changes with js, i.e.]
     return height;
}

At intervals of 400 ms, the function calculates the height of the loaded page (or element) and sets the object this.frames.status (this object can be write and read in cross domain situation!).

In the page containing the IFRAME, we set code like this:

<!-- this is for write value -->
<div id="div_height"></div>
<script type="text/javascript">

setInterval(function(){

   var iframe = document.getElementsByTagName("iframe")[0];

   if(iframe && iframe.document.frames.status != ""){


      document.getElementById("div_height").innerText = "now iframe has height of " + iframe.document.frames.status + " pixels";

      var h_iframe = parseInt(iframe.document.frames.status) + 150;
      iframe.style.height = h_iframe;
   }
}, 500);
</script>

At intervals of 500 ms, the function reads the value of the iframe.document.frames.status object, converts it to an integer and sets it as the height of the IFRAME (or other objects).

It works!

Tuesday, September 18, 2012

Sharepoint 2010 - Client Validation of a Custom Form with Javascript

What to do if you want to perform a client validation with Javascript, in your custom new/edit form.

The submit button cames with this code in onclick event:


if (!PreSaveItem()_) return false;WebForm_DoPostBackWithOptions(new ...

The PreSaveItem function invokes PreSaveAction function that you can override with your own definition.If PreSaveAction returns true, then form proceeds to save data, otherwise, it stops with alert.


With Sharepoint Designer 2010, open form with Edit in Advanced Mode and insert code below:


<!-- call jquery -->
<script type="text/javascript" src="/SiteAssets/js/jquery.min.js"></script>
<!-- override PreSaveAction -->
<script type="text/javascript">
function PreSaveAction()
   var field_to_validate = $("select[title='TITLE OF FIELD']").val();
   if(field_to_validate == ""){
     alert("Warning: complete field_to_validate!");
     return false;
   }
   return true;
}
</script>

We add jquery (but if you want to use simple javascript, you can).
Then, check field by title: in browser, input tag came with attribute "Title" equals to display name of column, then I search for this value.
If empty, return alert then false.


Wednesday, September 12, 2012

Sharepoint 2010 - Create a Site Collection Template without Errors...


(I know, the title of this post is misleading ...)

I had to create a template for Site Collection and, according to various posts and tutorials, the procedure seems very simple: Save site as template, Import into a new project in Visual Studio 2010, changing some scope, put into hidden some features and recompile.
Then, upload wsp on farm, deploy and so on ...

Everything is fine until I try to create a new Site Collection using the new template.
The page loading... and ... error "File not found"!!
In the log file, nothing about which files it is searchin for.

I found no solution, my template was not so complex, but did not understand why this error.

In the end, the lighting has arrived.

We know that is not possible (in theory) save a site as a template if it has the Publishing Feature activated.
"In theory", because through the direct link to the page, you can save it as template.
But Microsoft does not support this type of template (site with publishing feature activated), so they hide us the link.

In case of a top-level site of a site collection, even if Publishing Feature in NOT activated but, in Site Collection, Server Publishing Infrastructure Features is activated, we can Save site as model, BUT we get errors!

Activate Server Publishing Infrastructure Features creates some lists and libraries of type "publishing".
Unfortunately, turn them off  does not eliminate what was created and it seems that these items are the cause of the failure in create new site collection from template.
Although this does not give errors in creation, build and deployment.
And if we use this template for a new site in a Site Collection (yes, we can do), it's ok.

So, if you want to create a Site Template for a Site Collection, you DO NOT EVER activate the Server Publishing Infrastructure Features in Site Collection!

Lesson to learn..

Get QueryString Value with JQuery

I found this solution to get value of querystring with jquery.

Add jquery script to your page and insert this code in script to define the new function:

(function($) {
    $.QueryString = (function(a) {
        if (a == "") return {};
        var b = {};
        for (var i = 0; i < a.length; ++i)
        {
            var p=a[i].split('=');
            if (p.length != 2) continue;
            b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
        }
        return b;
    })(window.location.search.substr(1).split('&'))
})(jQuery);

Then, call it for your querystring parameter:

var q = $.QueryString["query"];

Fine!


Tuesday, July 10, 2012

Sharepoint 2010 - Full Crawl fails on Web Application with Access Denied Error

I started a Full Crawl of Content DataSource and I get this error message:

"Access is denied. Verify that either the Default Content Access Account has access to this repository, or add a crawl rule to crawl this repository. If the repository being crawled is a SharePoint repository, verify that the account you are using has "Full Read" permissions on the SharePoint Web Application being crawled"

even if I use an account with Full Read permission on that Web Application.

I go on Search Server machine for Sharepoint farm, with credential used for Default Content Access Account, and I try to navigate to site collection in that Web Application: I get error "Access Denied", browser asks me for credential and then "Error 401"..


So, the problem was that account used for Default Content Access cannot browse to site collections in Web Application, from the server search.

I correct with this post, from Microsoft: "You receive error 401.1 when you browse a Web site that uses Integrated Authentication..."
I followed Method 1 and works for me, very well!

Note: you can use method 2, but you have to restart computer, but method 1, you can restart only iis services..

Then, I go on Central Administration and Search Application Service, restart Full Crawl and.. it's all ok!



Thursday, July 5, 2012

Sharepoint 2010 - Show/Hide columns with Conditional Formatting

In a previous post I describe how show/hide columns of a list with UI language, using javascript.

Now, I show how do the same using Conditional Formatting feature of Sharepoint Designer 2010.

I have same list with columns for language, DescriptionIT, DescriptionEN.


Open Sharepoint Designer 2010, and edit page with list view.

Select List and add Parameter for language taken from Cookies:


Then, select tag <TH> for List Column DescriptionIT, using selector at the bottom of page:


Now, in the Condition Formatting panel, click on Create and Apply Formatting:


In the filter clause, click on Advanced and write code as below:


Then, click OK, and Set Style, in Layout section, set Display:none:


Click OK and OK again.

Repeat steps selecting <TD> tag for values of column DescriptionIT.
Do it again for DescriptionEN column, with condition "($cookieLanguage!='1033')".

Save page and view in browser, checking columns changing UI Language.



Tuesday, July 3, 2012

Sharepoint 2010 - Change UI Language with javascript

If you want to use html/javascript to change UI language, you can use the script below:
(Note: in the page, there is the function OnSelectionChange, so you have to change name if you want to use other feature in)

function OnSelectionChange(value)
{
    var today = new Date();
    var oneYear = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000);
    var url = window.location.href;
    document.cookie = "lcid=" + value + ";path=/;expires=" + oneYear.toGMTString();
    window.location.href = url;
}

And in page, set the flags for change language:

<a href="javascript:OnSelectionChange(1040)">
    <img width="32" height="20" src="/SiteAssets/flag_ita.png" border="0" alt="Italiano"/>
</a>
<a href="javascript:OnSelectionChange(1033)">
    <img width="32" height="20" src="/SiteAssets/flag_eng.png" border="0" alt="Inglese"/>
</a>

Sharepoint 2010 - Filter Web Part with Current User Language

I have to filter a List/Library on current User Language.
I add column Language Code, with values of platform language codes (1033 for english, 1040 for italian).



With Sharepoint Designer 2010, I modified Web Part and I set a new parameter as below, using COOKIE source parameter with "lcid" name:


and the filter :


So, web part shows me documents/items filtered with language = italian/english choosen by user!

For italian:
For english:



Friday, June 29, 2012

Sharepoint 2010 - Multilanguage Site - Show column in current language

In multilanguage site feature, Sharepoint 2010 does not translate content of web part and metadata.
We have to find a way to show to user content or metadata in current language.

I used a list with columns with content in language and a lot of jquery to show and hide columns for current language.



I have a list with "DescriptionIT" and "DescriptionEN" columns.
Then, I set a view with both columns visible.
In this view, I added a content query web part whit code below.

In this code, I search for current language, i.e. "Italian", then search for column with "DescriptionIT", and hide all columns but "DescriptionIT" (with name starting with "Decsription").

Result is that if I change language (with Select Display Language), I see only column in respective language.



Simple and cross platform.

Here the code:


<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">

function DisplayLanguage(column)
{

 var langCode = _spPageContextInfo.currentLanguage;

 var columnEnglish = column+"EN";
 var columnItalian = column+"IT";
 var columnChinese = column+"CH";
 var columnSlovacchia = column+"SL";
 var columnSpanish = column+"ES";

 //
 var parentThName;
 var parentTh;
 //
 switch(langCode)
 {
    case 1033:
parentThName = columnEnglish;
        break;
    case 1040:
parentThName = columnItalian;
        break;
    case 1028:
parentThName = columnChinese;
        break;
    case 1051:
parentThName = columnSlovak;
        break;
    case 1034:
parentThName = columnSpanish;
        break;
    default:
  parentThName = columnEnglish;
        break;
 }

 //get column id to show
 parentTh = $("div[name='"+parentThName+"']").parent();
 parentThIndex = parentTh[0].cellIndex;
 //get all ths with Description
 allTh = $("div[name^='"+column+"']").parent();
 allTh.each(function(item){
    //hide all column but language column
    if($(this).index() != parentThIndex)
    {
  //hide
$(this).hide();
//get its id
var indth = $(this)[0].cellIndex;
//hide all cell of this column
$("td.ms-vb2").each(function(item){
   if($(this).index() == indth)
   {
$(this).hide();
   }
        });
    }
 });
}

DisplayLanguage("Description");

</script>


Friday, June 8, 2012

Sharepoint 2010: BeforeProperties and AfterProperties in Event Receivers!

Event Receiver is a great feature for Sharepoint 2010, but I spent many time to discover how Properties works..
Especially BeforeProperties and AfterProperties..

I found a great post with resume all available values. Here table and below the link!

http://www.synergyonline.com/Blog/Lists/Posts/Post.aspx?ID=122

These are the values of the properties in List events:
ListBeforePropertiesAfterPropertiesproperties.ListItem
ItemAddingNo ValueNew ValueNull
ItemAddedNo ValueNew ValueNew Value
ItemUpdatingNo ValueChanged ValueOriginal Value
ItemUpdatedNo ValueChanged ValueChanged Value
ItemDeletingNo ValueNo ValueOriginal Value
ItemDeletedNo ValueNo ValueNull
And here are the properties available in Library events:
LibraryBeforePropertiesAfterPropertiesproperties.ListItem
ItemAddingNo ValueNo ValueNull
ItemAddedNo ValueNo ValueNew Value
ItemUpdatingOriginal ValueChanged ValueOriginal Value
ItemUpdatedOriginal ValueChanged ValueChanged Value
ItemDeletingNo ValueNo ValueOriginal Value
ItemDeletedNo ValueNo ValueNull

Thursday, June 7, 2012

Sharepoint 2010: Deactivate and Activate Feature with Power Shell

Sometimes, you can have trouble with feature upgrade in your site.
Especially if you upgrade event receiver, adding new trigger.
If you have many sub site using this feature, you can use Power Shell to deactivate and activate feature.

This mine:


[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$rootUrl = "http://[SERVERNAME]"
$site = Get-SPSite $rootUrl
foreach($web in $site.AllWebs)
{
  $url = $web.Url
  if($url -ne $rootUrl){
   foreach($feature in Get-SPFeature -Web $url)
   {
    $featureName = $feature.DisplayName
    if($featureName -eq "FEATURE NAME")
    {
      "Disable and Enable feature $featureName in $web"
      Disable-SPFeature -Identity FEATURENAME -Url $url -Confirm:$false
      Enable-SPFeature -Identity  FEATURENAME -Url $url
      break;
    }
   }
  }
}

Sharepoint 2010 Globally Reusable Workflows does not update WF instance in Subsite if re-published: PS Script save me

I defined a Globally Reusable WF for a custom Content Type in root site, with a custom form with InfoPath.
I defined a sub site with a list using the global WF template created for its Content Type.
Everything works without problems.

Now I need to change the WF (both in form and in the process).
BUT..
If I edit only the form with InfoPath and then I publish the form, I see correctly the new form in WF on subsites.
If I change the WF logic too (any actions) and publish WF (in root site), changes are not perceived by WF on subsites.
WF on subsite is updated only if, on subsite, I open WF to change (from browser) and save it.

I expect that you can update all WF in subsite using template in root site, without having to reopen and resave each WF in each subsite.
I don't understand if it's a bad configuration or a issue on Globally Reusable WF.

(I opened question in Technet Forum, here)

UPDATE: Sometimes, I update a WF (form and logic) and logic has been correctly published in all web site, but form does not show my modification...

So, unique solution I found for all my subsites is to delete workflow association and recreate it, for each site... But it's a long task, depend on how many subsites you have.

I write this powershell script to automate removing and adding operation.
This helps me, but cannot solve problems..
If you don't have access to Server to run PS Scripts, you cannot use this way...


[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$urlRoot = "http://[SERVER]"
#array of workflow name to update
$wfNames = "Workflow Name 1"," Workflow Name 2", "Workflow Name 3"

$site = Get-SPSite $urlRoot

foreach($web in $site.AllWebs){

 $url = $web.Url

 #exept for root site (if needed)
 if($url -ne $urlRoot){

   foreach($wfName in $wfNames){

     "Adding workflow $wfName to $url"

     $list=$web.Lists["LISTNAME"]
     $taskList=$web.Lists["WF TASK LIST NAME"]
     $historyList=$web.Lists["WF HISTORY LIST NAME"]
     $ct=$list.ContentTypes["CONTENT TYPE"]

     "Search workflow $wfName"
     foreach($wf in $ct.WorkflowAssociations)
     {
       if($wf.Name -eq $wfName)
       {
         "Remove workflow $wfName"
         $ct.WorkflowAssociations.Remove($wf)
         break;
       }
     }

     "Now add workflow $wfName"

     $culture=New-Object System.Globalization.CultureInfo("en-US")
     $wfTemplate=$web.WorkflowTemplates.GetTemplateByName($wfName,$culture)

     "Get wf template"
     $associationWF=[Microsoft.SharePoint.Workflow.SPWorkflowAssociation]::CreateListContentTypeAssociation($wfTemplate, $wfName,$taskList,$historyList)

    "Add Workflow $wfName"
     $ct.WorkflowAssociations.Add($associationWF)
     $ct.UpdateWorkflowAssociationsOnChildren($true,$true,$true,$false)
  }
 }
 $web.Dispose()
}

Thursday, April 5, 2012

Will SharePoint 15 (2013) finally get an App Store?


by Mark Jones | Jan 31, 2012
Just decided to have a few minutes investigation into the recently released SharePoint 15 Technical Preview Managed Object Model SDK to see if there is any insight into what's coming up!
Before I get started, please note this information is all deduced from the Object Model documented in the SDK and is solely my opinion of what "may" happen. The SDK clearly states that it is "subject to change", so don't bet the crown jewels on anything in this post!

The SPApp Store classes

(SPApp, SPAppCatalog, SPAppInstance, SPApplicationCredentials, etc.)
Picture showing SharePoint 2013 AppStoreWell, it looks like SharePoint's going to get some tight integration with an App Store (aka market place). This has been on the cards for quite a while, but I thought they'd have to get the API developed to support it eventually. Reading between the lines, I think there's going to be somewhere in the SharePoint GUI to browse for an "App" in an on-line App Store. Once selected you will pay (or trial it) then using the SPWeb's new LoadAndInstallApp() method it will stream the App into the App database (and install it as a Sandboxed solution). It's more than likely going to be be a bit like the Web Part Gallery on steroids - (I also wouldn't be suprised if the web part gallery gets replace with the 'Corporate Catalog' see below). 
I would also imagine there's a few timer jobs that poll the "App Store" (or package source) to check for updates and 'news'. Obviously, this is all guess work based on looking at a few barely documented classes, but it's fun! It also looks like there is a method at the web application level to see if a user is licensed, which again adds weight to new App Store support!

SharePoint 2013 supports OAuth

The other really interesting find is around support for OAuth. If you don't know what OAuth is then think of it as way for you to give one site (e.g SharePoint) the rights to use assets from another (e.g. Facebook), without having to store user names and passwords. This is how LinkedIn, Facebook, Twitter grant all the 3rd party apps the rights to use your data from those accounts. I think - as this is going to be baked into SharePoint - I can see a lot of cross-fertilization with other external social networks. For example, imagine LinkedIn contacts merged into your internal colleagues on your MySite? Or, your Twitter feed mixed into the Activity feed and so on. This opens up lots of possibilities and is probably essential now that the line between home and work are blurring.

App Store Database Provider

Other evidence to support the introduction of a new App Store is the addition of a new Database Provider set of classes. It looks like when a 'package' is download it will be configured to use any back-end database that supports the new Database provider interfaces. I imagine there will be concrete implementations for SQL and SQL Azure to start with. 

App Store sources?

One cool thing to note is the introduction of the Microsoft.SharePoint.Administration.DatabaseProvider.PackageSource' Enum. If you look at the list below, you will not all of the different sources that can 'serve' up an app package :
  • Store Front
  • Corporate Catalog
  • Developer Site
  • Object Model
  • Remote Object Model
Very interesting times ahead! I think we may just have to think about making DocRead our 'read and acknowledge solution' App Store ready - sooner that we thought! The only question I have now is around the App Stores, will there be 1 - managed by Microsoft, or will they offer the API out to others? The doc isn't clear yet, but lets wait and see!

Thursday, March 8, 2012

Sharepoint 2010 - Assign Category to your Site Template (without VS)

Set your Site Template in a Category is (maybe) simple with Visual Studio, but not the faster way.
I tried with success by editing some xml in WSP package. Here step by step my solution.

Save your site as template, "My_Site".
Go in Solutions Gallery and download your My_Site.wsp package on desktop.
Rename extension from .wsp to .cab.
Use your tool to extract and create CAB archive, I used SimplyZip.
Extract My_Site.cab and open to edit file Elements.xml in folder “My_SiteWebTemplate”.
Add attribute DisplayCategory="My Site Templates" in tag “<WebTemplate>” and save file.
Use your tool to create new file My_Site.cab with all files from original cab and modified file.
Note: with SimplyZip use Drag&Drop to set files and folders to add in cab.
Change extension from .cab to .wsp and upload My_Site.wsp on Solutions Gallery.
Now, try to create new Site: in the "Filter By:" section, you see My Site Templates category, and your My_Site site template in.



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.

DocShare1.gif

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
                    docLibrary.Update();
                }
            }

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

DocShare2.gif

C#:
docLibrary.ContentTypesEnabled = false;

PowerShell:
$docLibrary.ContentTypesEnabled = $false

Opening Documents in the Browser:DocShare3.gif

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

PowerShell:

#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: 

DocShare4.gif

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


PowerShell:

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

Folders: 
DocShare5.gif

C#:
docLibrary.EnableFolderCreation = false;

PowerShell:
$docLibrary.EnableFolderCreation = $false

Search:

DocShare6.gif

C#:
docLibrary.NoCrawl = true;

PowerShell:
$docLibrary.NoCrawl = $true

Offline Client Availability:DocShare7.gif

C#:docLibrary.ExcludeFromOfflineClient = true;

PowerShell:

$docLibrary.ExcludeFromOfflineClient = $true

Site Assets Library: 

DocShare8.gif

C#:
docLibrary.IsSiteAssetsLibrary = false;

PowerShell:
$docLibrary.IsSiteAssetsLibrary = $false

Datasheet: 

DocShare9.gif

C#:
docLibrary.DisableGridEditing = true;

PowerShell:

$docLibrary.DisableGridEditing = $true
Dialogs: 

DocShare10.gif

C#:

docLibrary.NavigateForFormsPages = true;

PowerShell:

$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:

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$site=Get-SPSite "http://sharepoint_root_site"

foreach($web in $site.AllWebs){
   $list=$web.Lists["MyList"]
   $taskList=$web.Lists["Workflow Tasks"]
   $historyList=$web.Lists["Workflow History"]
   $ct=$list.ContentTypes["MyContenType"]
   $culture=New-Object System.Globalization.CultureInfo("en-US")
   $wfTemplate=$web.WorkflowTemplates.GetTemplateByName("wfTemplate", $culture)
   $associationWF=[Microsoft.SharePoint.Workflow.SPWorkflowAssociation]::CreateListContentTypeAssociation($wfTemplate, "MyWFInSubSite", $taskList,$historyList)
   $ct.WorkflowAssociations.Add($associationWF)
   $ct.UpdateWorkflowAssociationsOnChildren($true,$true,$true,$false)
}

It helps me for massive update.