vendredi 27 décembre 2013

Sharepoint Error: Save Conflict Your changes conflict with those made concurrently by another user

If you develop Sharepoint components that modify list items, you might know this error:
Save Conflict
Your changes conflict with those made concurrently by another user. If you want your changes to be applied, click Back in your Web browser, refresh the page, and resubmit your changes.
This happens whenever you try to save a SPListItem which has been modified since you opened it. Review your code to ensure that you don’t open the same list item multiple times, work with a single SPListItem object instead.
Sometimes however it is necessary to open the same list item in parallel, as example if you want to perform an operation with elevated privileges on the item. If you take this approach you need to ensure that if you save one of the SPListItem objects, you need to reload all other SPListItems that point to the same actual item. Otherwise you’ll get the error above whenever you perform a change on the outdated items.
You can use the following utility method to ease the reloading of items:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/// <summary>
/// Reload a list item from scratch
/// </summary>
/// <param name="item">The list item</param>
/// <remarks>
/// Useful to avoid save conflicts
/// </remarks>
/// <returns></returns>
public static SPListItem ReloadListItem(SPListItem item)
{
    if (item == null)
        return null;
 
    return item.ParentList.GetItemByUniqueId(item.UniqueId);
}

vendredi 13 décembre 2013

SharePoint 2010 / 2013 Get all groups for SPUser including active directory group

SharePoint don't give you groups for SPUser if the right is given by an active directory group.

You have to merge groups specificied directly using user login in sharepoint groups and active directory groups.


private static List<SPGroup> GetAllUserGroups(SPUser user)
{
    List<SPGroup> groups = new List<SPGroup>();
    //Get groups from SharePoint
    foreach (SPGroup spGroup in user.Groups)
    {
        groups.Add(spGroup);
    }
    string userLogin = user.LoginName;

mercredi 10 juillet 2013

SharePoint 2013 , change branding text content

Purpose

You can easily change the SharePoint branding text that appear in the left corner of you site thanks to this powershell code

PowerShell Snippet

Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
$webApp = Get-SPWebApplication http://serveurSP
$webApp.SuiteBarBrandingElementHtml = "Larry's Microsoft Technologies Blog"
$webApp.Update()


 Following this example you can also change the background color using CSS :
/* Modification couleur de la barre d'application */
/*Modification de la couleur du texte de la barre d'application */
#suiteBarLeft
{
background-color: rgb(229,226,221);
color: rgb(0,0,0);
font-weight:bold;
padding-left:5px;
}
This is the final result with suite bar color modification and brand text changing.