Most Valuable Professional – SharePoint Server #2

MVP Logo92

Hello everyone,

 

Yesterday I had the honor to receive the title of Most Valuable Professional – SharePoint Server for the 2nd consecutive year! It is always a pleasure to contribute to the community given the help I can find thanks to others contributions. This is really an example of WIN-WIN relationship!

 

MVP Profile: http://mvp.microsoft.com/en-us/mvp/Christopher%20Clement-5000232

From http://blogs.msdn.com/b/mvpawardprogram/archive/2014/07/01/new-and-renewed-mvps-announced-today.aspx

“While there are more than 100 million social and technical community members, only a small portion are selected to be recognized as MVPs. Each year, around 4,000 MVPs are honored. They are nominated by Microsoft, other community individuals, or in some cases themselves. Candidates are rigorously evaluated for their technical expertise, community leadership, and voluntary community contributions for the previous year. They come from more than 90 countries, speak over 40 different languages, and are awarded in more than 90 Microsoft technologies. Together, they answer more than 10 million questions a year!”

 

A big thank you to Microsoft for this award!

Christopher

Most Valuable Professional – SharePoint Server

MVP Logo92


Hello everyone,

It is now one year and a half that I write on this blog and I am active on the msdn forums. It is always a pleasure to see a response to a forum or article helps someone. I was already happy to see the number of visits to my blog, but today I had the honor to receive this e-mail

« Chère/Cher Christopher Clement,

Félicitations! Nous sommes heureux de vous remettre la récompense MVP Microsoft® 2013! Cette récompense est accordée aux leaders d’exception de la communauté technique qui partagent activement leur expertise pratique de grande qualité. Nous apprécions vos remarquables contributions dans les communautés techniques SharePoint Server lors de cette année passée.

La nomination des Microsoft MVP est pour nous une occasion unique de reconnaître vos contributions de valeur et de vous dire « Merci pour votre participation technique ».

I do not know what to say other than thank you! What an honor to receive this award!

I especially want to thank Sebastian Sougnez and David Petrocelli who gave me the necessary confidence to begin to contribute to the community! Thank to both of you!

Christopher.

CAML Query – Show element not assigned to me or my groups

SP2013

Hello everyone,

Some time ago, I made a summary post on « Filter on current user and current user groups »

This query uses the “membership” parameter to recover the current user groups. However, some time ago, a request was made on the msdn forums for reverse query! Namely, retrieve elements which are not assigned either to the current user or to one of its groups!

After doing several tests, I did not find any conclusive parameter and I turned to a solution of dynamic creation of the query.

Here it is


SPQuery query = new SPQuery();

query.Query = CreateQuery(web.SiteGroups);

.....

string CreateQuery(SPGroupCollection groups)

{

string queryToReturn = "<Where>";

int countAnd = 0;

List<string> listGroupName=new List<string>();

//Get list of group Name and count the number

foreach (SPGroup group in groups)

{

if (group.ContainsCurrentUser)

{

listGroupName.Add(group.Name);

countAnd++;

}

}

//If there is a least one group where the current user is in, we will need an 'And' and to add all the possibilities

if (countAnd > 0)

{

queryToReturn += "<And>";

for (int i = 0; i < countAnd - 2; i++)

{

queryToReturn += string.Format(@"<And><Neq><FieldRef Name='BelongsTo'/><Value Type='User'>{0}</Value></Neq>", listGroupName[i].ToString());

}

queryToReturn += string.Format(@"<Neq><FieldRef Name='BelongsTo'/><Value Type='User'>{0}</Value></Neq>", listGroupName[countAnd - 1].ToString());

for (int i = 0; i < countAnd  - 2; i++)

{

queryToReturn += @"</And>";

}

}

queryToReturn += @"<Neq><FieldRef Name='BelongsTo'/><Value Type='Integer'><UserID/></Value></Neq>";

//Close the And tag if needed

if (countAnd > 0)

{

queryToReturn += "</And>";

}

queryToReturn += "</Where>";

return queryToReturn;

}

Some explanations:

This function will do a check of all the groups in the collection, if the user is present in the group, a counter is incremented and the group name is saved in a list. Then the query is build based on those elements.

Hope this helps !

Christopher

Service Unavailable

SP2013

Hello everyone,

Today, I’ll talk about a « To Remember ».

Sometimes after an action on the SharePoint server you receive the following error message trying to access your SharePoint
01
By “action” I mean for example:

  • Installation / deployment of a package
  • Updating a cumulative update

If it happens, check in the “Internet Information Services (IIS) Manager” that pool applications are started!

Often, one or more of them will not restart properly.
02
Important: make this check on all front-ends of your SharePoint farm!

Reminder:

To see this manager, enter “inetmgr” in the command prompt of the server (windows key + R shortcut), then click on your server on the “Application pool” tab.

Christopher.

SharePoint DateTime incorrect hour?

SP2013

Hello everyone,

Today I’ll talk about a problem that I had when I wanted to compare dates.

The problem I had was that the time displayed was different from the time that I was recovering through my code! 2h difference to be exact.

After searching for a long time, it turns out that the “problem” was how SharePoint stores dates. Indeed SharePoint converts dates to UTC … that’s why my comparison was not good!

So when you want to work in code behind with dates, do not forget to convert to UTC!

For this, two methods:

SPTimeZone.UTCToLocalTime et SPTimeZone.LocalTimeToUTC

I met the problem on a 2010 environment but in my opinion it should be the same in 2007 and 2013.

Hope this helps!

Christopher.

Tool for CAML Query


Hello everyone,

For those who do not know, there is a tool to generate your CAML queries.

This utility is the work of Karine Bosch and Andy Van Steenbergen

For SharePoint 2003 and 2007 we had the CAML Builder tool, you can it find here: http://www.u2u.be/res/tools/camlquerybuilder.aspx

Recently there was a new version of the CAML Builder targeting SharePoint 2010 and SharePoint Online: CAML Designer.

You can find all information here: http://karinebosch.wordpress.com/my-articles/caml-designer/

If you have to create CAML queries, do not hesitate one second!

Christopher.

Get field value during an event handler.


Hi everyone,

Today I will talk about “event handler” and more specifically those used on elements of lists and libraries.

3 types of events are attached to the lists and libraries: Adding, updating and deleting

Each of its events can be retrieved synchronously (at the time of the action) andasynchronous (right after the end of the action).

It’s very easy to spot if a function is synchronous or asynchronous based on its name.

Action

Synchronous

Asynchronous

Adding an item

ItemAdding

ItemAdded

Updating an item

ItemUpdating

ItemUpdated

Deleting an item

ItemDeleting

ItemDeleted

As you can see, synchronized action’s name ends with “ing” and asynchronous with “ed”.

During these actions, we can know the field values and sometimes the previous value of the field. Ways to retrieve data are:

Properties.ListItem[«FieldName »]

Properties.AfterProperties[«FieldName »]

Properties.BeforeProperties[«FieldName »]

And yes, three possibilities depending on the actions and the synchronicity of the eventcan contain either the new value, or the old value, or nothing at all! And where it reallygets tough, it also depends on the type of list, whether the current list is a list or library.

Given this number of possibilities a little summary table seemed necessary, here it is.

For the lists

Event

ListItem

BeforeProperties

AfterProperties

ItemAdding

X

X

New value

ItemAdded

New value

X

New value

ItemUpdating

Old value

X

New value

ItemUpdated

New value

X

New value

ItemDeleting

Old value

X

X

ItemDeleted

X

X

X

For the libraries :

Event

ListItem

BeforeProperties

AfterProperties

ItemAdding

X

X

X

ItemAdded

X

X

New value

ItemUpdating

Old value

Old value

New value

ItemUpdated

New value

Old value

New value

ItemDeleting

Old value

X

X

ItemDeleted

X

X

X

Those informations are very important to consider when planning a development.

Additional information that is important is that during the upload of a document by a user in a library, adding events are triggered after addition of the upload but before the user can fill in themetadata! This filling triggering the updating events.

If you plan to modify the contents of the properties of this document at the event”ItemAdded”, your users may see a message like this when they will safeguard their metadata:

“File ‘mydoc.pdf’ has been modified by ‘user’ the ‘date'”.

To avoid this error, we can define the event “ItemAdded” as synchronous! Indeed, all asynchronous event can be defined as synchronous!

This will allow us to pre-fill the data in our forms before the user does not grasp anything! Given the asynchronous nature of the ItemAdded, if you change the data content, you are not 100% sure that the form displayed to the user include the new data and thus avoid conflicts backup.

For this we must add the synchronization parameter to our xml definition.


<Receiver>
<Name>EventReceiver1ItemAdded</Name>
<Type>ItemAdded</Type>
<Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
<Class>TutoTaxonomy.EventReceiver1.EventReceiver1</Class>
<SequenceNumber>10000</SequenceNumber>
<Synchronization>Synchronous</Synchronization>
</Receiver>

In our code we add an update of the column “test”


public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdded(properties);
properties.ListItem["test"] = "test synchro";
properties.ListItem.Update();
}

And now, with this little trick our form is pre-filled every time!

Hope this helps!

Christopher.