Albert Jan Schot
 

Create a custom group in the SharePoint Ribbon

20

Jul

Creating custom ribbon commands is all inline with the SharePoint User Experience, and thus something you should keep in mind whenever you are developing for SharePoint 2010.  However I found myself in need of creating a new group within an existing tab and stumbled upon the next MSDN article, however a minor detail is that you cannot add a CommandUIHanlder without a CommandAction. So in order to get the script working you have to delete the line with Command="EnableCustomGroup" and the line with <CommandUIHandler Command="EnableCustomGroup" />.

Leaving you with a script like you can find below to create a custom group:

  1: <?xml version="1.0" encoding="utf-8"?>
  2: <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  3:   <CustomAction 
  4:     Id="Ribbon.WikiPageTab.CustomGroupAndControls" 
  5:     Location="CommandUI.Ribbon" 
  6:     RegistrationId="100" 
  7:     RegistrationType="List">
  8:     <CommandUIExtension>
  9:       <CommandUIDefinitions>
 10:         <CommandUIDefinition 
 11:           Location="Ribbon.WikiPageTab.Groups._children">
 12:           <Group 
 13:             Id="Ribbon.WikiPageTab.CustomGroup" 
 14:             Sequence="55" 
 15:             Description="Custom Group" 
 16:             Title="Custom Group" 
 17:             Command="EnableCustomGroup" 
 18:             Template="Ribbon.Templates.Flexible2">
 19:             <Controls Id="Ribbon.WikiPageTab.CustomGroup.Controls">
 20:               <Button
 21:                 Id="Ribbon.WikiPageTab.CustomGroup.Controls.CustomButton1" 
 22:                 Command="CustomButtonCommand1" 
 23:                 Image16by16="/_layouts/images/FILMSTRP.GIF" 
 24:                 Image32by32="/_layouts/images/PPEOPLE.GIF" 
 25:                 LabelText="" 
 26:                 TemplateAlias="o2" 
 27:                 Sequence="15" />
 28:             </Controls>
 29:           </Group>
 30:         </CommandUIDefinition>
 31:        </CommandUIDefinitions>
 32:       <CommandUIHandlers>
 33:         <CommandUIHandler Command="EnableCustomGroup" />
 34:         <CommandUIHandler Command="CustomButtonCommand1" 
 35:           CommandAction="javascript:alert('Hello, world!');" />
 36:       </CommandUIHandlers>
 37:     </CommandUIExtension>
 38:   </CustomAction>
 39: </Elements>

Albert-Jan Schot schreef

Comments (0)

Albert-Jan Schot

How to generate XML for Colligo

18

Jun

Colligo allows you to sync SharePoint lists and libraries to your computer, and since Office 2003 won’t recognize memberships pulled from a SharePoint 2007 environment by default, one of your customers choose this tool to have a save-as functionality option in Office 2003. The idea was to auto generate the xml file that is readable by Colligo so each user would have a set of sites to save to.

First things first, the documentation on how you can create such an xml file can be found here  and a demo xml file can be found here (xsd can be found here). Knowing that makes it pretty easy to generate the xml you require. Two things to keep in mind:

  • Don’t use comments in your XML file, Colligo just won’t import it.
  • If you auto generate the xml multiple times, make sure to delete the file after Colligo imported it, otherwise it tries to import it again (and fails) the next time you start Colligo

So creating XML files for Colligo made easy.

Albert-Jan Schot schreef

Comments (0)

Albert-Jan Schot

Tired of waiting for membership updates on your devmachine?

17

Jun

Building code that retrieves memberships most of us will do by using the Publishedlinksservice that returns all the memberships. However normally those memberships only update every hour, so if you have a development machine and you want to test code (or check whether the memberships actually get updated), you are stuck waiting. Sadly you cannot force an update on the timer job that syncs those memberships; luckily you can speed up things, the STSADM sync operation allows you to set the time it takes between syncing.  So the next command will force the timer job to sync every minute:  

stsadm -o sync –SyncTiming M:1

This might cause some load, but on my development machine I don’t really care about that, as long as I can see results. And of course you can set it back to its original 60 minutes afterwards.

Share:

Albert-Jan Schot schreef

Comments (0)

Albert-Jan Schot

SharePoint 2010 Search Page and the UIVersionedContent control

27

May

The default SharePoint 2010 Search center has a nice predefined results page for you, containing a nice set of WebParts. However if you create a Search Center you can see that returning to your site is a pretty hard task. So today someone asked me if we could make a page-layout exactly like the default search results page, allowing them to create resultpages anywhere in their portal. That being said, the only thing I had was the SharePoint Designer, luckily for me it was a 2010 project :).

So first thing I did was copying the default WelcomeLinks.aspx pagelayout, since that page has no left sidebar, next thing was to simply copy the table structure to the page and tweaking it a bit. However after checking it in, and publishing it, I got stuck with an unknown error. After some debugging my logs shows the error:

Exception No parameterless constructor defined for this object.

After some more debugging it seems that one of the WebParts on the default search page got an invalid property, so after deleting all the WebParts, leaving me with an empty page with nothing but some WebPartZones I checked it in, and published it again. Just to bring me the next error:

Unknown server tag 'SharePoint:UIVersionedContent'.

For some reason the WelcomeLinks.aspx is allowed to use the UIVersionedContent, but as soon as you ‘customize’ it, you aren’t anymore. Adding the next line will do the trick:

<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

After that you’re good to go, and you will have a nice SearchResults look-a-like pagelayout.

Result:

SearchResults.zip (2.08 KB)

Albert-Jan Schot schreef

Comments (0)

Albert-Jan Schot

SDN 18 may 2010 : PowerShell and SharePoint

26

May

Last week I gave a presentation on PowerShell and SharePoint. The main focus was on showing the cool stuff from PowerShell and giving an introduction into new possibility’s it has for both developers and admins. More on the event itself can be found on: http://www.sdn.nl/SDN/SDNEvent/SDNEventMei2010/tabid/160/Default.aspx (Dutch).
For those who are interested the slides and code examples can be found here:

PowerShell.ppt (164 KB)
PowerShellDemos.zip (4.54 KB)

Both are in Dutch.

Albert-Jan Schot schreef

Comments (0)

Albert-Jan Schot

Start crawling with PowerShell

21

Apr

For our first ‘big’ project for SharePoint 2010 we started with some automated roll-out, using PowerShell. So whenever we do a build we can easily deploy ‘everything’ that is in our features, and since we deploy some content trough features we needed to update the search.

Instead of updating it through code we used PowerShell to start crawling the content we just deployed. That way you can keep from creating featurereceivers doing your deployment stuff, seems to be quite easy actually to do things with PowerShell; all you need is some time finding the things you need.

Like you can see on the SharePoint 2010 Search Wiki there are quite some cmdLets available, digging in them a bit more you can retrieve almost all information you need with: Get-SPIisWebServiceApplicationPool

The fact that you can combine that with other calls you can even get more with cmdlets like Get-SPEnterpriseSearchCrawlContentSource

Combining those allowing you to get your contentsource, that you can use to start crawling it:

$CrawlContent = Get-SPEnterpriseSearchServiceApplication| Get-SPEnterpriseSearchCrawlContentSource

Check all members of your $CrawlContent with a $CrawlContent | Gm to check what you can do with it.

I used the $CrawlContent.CrawlStatus to check whether i should crawl or not

if ( $CrawlContent.CrawlStatus  -eq "Idle" ) {
        $CrawlContent.StartIncrementalCrawl()
    }

So finaly you end op with something like :

$CrawlContent = Get-SPEnterpriseSearchServiceApplication| Get-SPEnterpriseSearchCrawlContentSource

if ( $CrawlContent.CrawlStatus  -eq "Idle" ) {
        $CrawlContent.StartIncrementalCrawl()
    }

$CrawlContent.CrawlStatus

Albert-Jan Schot schreef

Comments (1)

Albert-Jan Schot

UserProfile and ChoiceLists, reading and saving

19

Feb

Last few days I have been struggling with a piece of code that should update a UserProfile. The idea was to make a nice feature that allows a WebPart to display a link that would open a screen showing the user some options to change UserProfile values. Those change options should be rendered based on three pieces of information; a Site Column containing possible values, a ControlType and the UserProfileProperty to save it to.

The first few versions worked pretty well since I only had to save strings or checkboxes, however further along the way I decided that ChoiceLists from the UserProfile should be supported, and there it all went wrong, even with Google it took me quite some time figuring out how to do it, so here a few tips: 

Saving a single value to a UserProfileProperty even when its a ChoiceList is pretty easy:

    userprofile[item.Key].Value = item.Value;

Saving multiple values to a userProfileProperty took me some more time, but finally even that appeared to be possible:

   foreach (string choice in choiceList)
   {
      userprofile[item.Key].Add((Object)choice);
   }

Minor detail on that part appeared that the .add option does as it says, it only adds items; ergo if you would already have selected option1 in your profile, and try to update it with an option2, it would keep the option1 saved, and adds the option2.

So before you are actually try to save values that way do a:

   userprofile.clear();

   userprofile.update();

Now that’s for ‘saving’ values to your UserProfile, reading them is another story, reading a ‘normal’ string can be done with a simple:

   userprofile["PropertyToRead"].Value;

Reading a ChoiceList should be done like:

   if (userprofile["PropertyToRead"] is UserProfileValueCollection)
            clValue = userprofile["PropertyToRead"] as UserProfileValueCollection;

Whenever you done that you can simple loop trough the UserProfileValueCollection for reading the selected items.

Albert-Jan Schot schreef

Comments (0)

Albert-Jan Schot

SharePoint: The security validation for this page is invalid

08

Jan

Today I found myself running into the ‘famous’ “The security validation for this page is invalid” error and it cost me quite some stress figuring out what went wrong, and why I wasn’t allowed to do what I wanted, a simple change to a user profile.

The thing is that everything worked fine, until I actually added the UserProfile.Commit() to apply the changes to my profile. So after some searching the web for something that could help me further (besides the run with elevated privileges), and some help from my colleague Peter we found the following article: The security validation for this page is invalid.

Basically the idea is: forget the AllowUnsafeUpdates(); and add a FormDigestControl to the page you are working on, as you can see it only takes a reference: 

<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

And a control:

<SharePoint:FormDigest runat=server/>

Further info can be found on the mentioned blog.

Albert-Jan Schot schreef

Comments (0)

Albert-Jan Schot

Exporting Site Columns

11

Dec

If you ever want to export site columns from an existing site collection, you might find yourself in a bit of a loop, since its quite hard to get a nice ‘export’ of all those columns if your no developer. So when I found out Gary had done that before I thought it was worth a blog.

Just some plain information about ‘exporting’ site columns from an existing site collection:

http://stsadm.blogspot.com/2008/02/export-site-columns.html 

The actual download can be found here:

http://stsadm.blogspot.com/2009/02/downloads.html

I did blog before about them extensions and the use of them in case of Ghosting.

Albert-Jan Schot schreef

Comments (0)

Albert-Jan Schot

SharePoint Search and the HOSTS File

30

Nov

I just ran into a nice SharePoint problem that is being described and resolved over here. Apparently there is a job trying to access your HOSTS file, in order to add some lines for the Search, and if it doesn’t have sufficient rights it complains about it. Whenever you decide to add users and give them ‘fulltrust’ it just deletes the host file..

So whenever you see your log filling up with:

Application Server Administration job failed for service instance Microsoft.Office.Server.Search.Administration.SearchServiceInstance

Reason: Access to the path ‘C:\WINDOWS\system32\drivers\etc\HOSTS’ is denied.

Or:

Application Server Administration job failed for service instance Microsoft.Office.Server.Search.Administration.SearchServiceInstance

Reason: Access to the path ‘C:\WINDOWS\system32\drivers\etc\HOSTS’ is denied.

Make sure that COMPUTERNAME\WSS_ADMIN_WPG has modify permissions on your HOSTS file. Whenever the HOSTS file is already gone, just create a new empty file with notepad and save it as HOSTS without an extension. (Make sure to add the COMPUTERNAMWSS_ADMIN_WPG with modify permissions after that again).

Albert-Jan Schot schreef

Comments (0)

Albert-Jan Schot