venerdì 25 maggio 2012

Inject javascript code to SharePoint 2010 Save button on New, Edit or Disp Form

Sometimes you want to execute a piece of javascript just BEFORE saving the item to SharePoint on a New, Edit or Disp form. Maybe you want to validate some fields on the form or want to set some default values or enable/disable some controls. SharePoint 2010 helps us by calling, by default, a PreSaveItem() function when you click the "Save" button. If this function returns true, the item is saved, if not, the saving process aborts: So, to inject your code all you have to do is defining, inside your NewForm.aspx, EditForm.aspx or DispForm.aspx, a function called PreSaveAction(), in a javascript block, that returns true or false. This custom function will be automatically called by SharePoint's PreSaveItem() function just after you click the button and just before the saving process starts:

giovedì 1 marzo 2012

[SharePoint 2010] Programmatically setting alternative language on a SPWeb

If you want to programmatically set alternative languages on a SPWeb all you have to do is to use the function below: Please note that this function activates ALL language packs you have installed on SP2010. If you want to activate only one, then some modifications are needed to the above code.

venerdì 24 febbraio 2012

[SharePoint 2010] SharePoint and Cross Site LookUp fields

When developing a large SharePoint project you may need a cross site lookup field and usually first thing you do is rush to google and search for someone who had the same problem as you and resolved it creating a custom field type and sharing source code. Today I hope to say something that could help someone to better use his time :)

I recently discovered that SPFieldLookup object comes cross site out of the box, even if SharePoint 2010 web user interface doesn't show this. You can  obviously use object model to create a lookup field that retrieves values from a list residing in a SPWeb that's not the SPWeb your lookup field lives in.

Below you can see a working example:

mercoledì 22 febbraio 2012

[SharePoint 2010] Provisioning did not succeed. Details: cannot initialize some site properties on ... OriginalException: Specified method is not supported.

Sometimes you create a custom webtemplate and, when instantiating it as a new spweb you get the following error:

Provisioning did not succeed. Details: cannot initialize some site properties on [your_site_url] OriginalException: Specified method is not supported.

In my tests I received the error code -2130246262 and a FAILED hr detected (hr = 0x8107058a) exception.

This is a really annoying error but I found out that maybe you left a masterpage or some other resource used by your webtemplate definition not checked-in or not approved in the SPSite or SPWeb sites.

Checking-In and Approving the offending resource corrects the error.