An attempt to share my day-to-day SharePoint experience

Archive for the category “C#”

I created a web part for work last week to batch-update the items of a SharePoint 2010 list.
To make it simple I will show how to modify only one column in the whole list using CAML and you can simply expand the idea. My site is called “SampleSite” and the list is “SampleList”. We are modifying the column “SampleColumn”. Here is how the code looks like:

I just got this error while developing a web part to batch update a SharePoint list. The solution was adding one line of code that allows running the update command on a list without requiring a security validation. This should be place right before your update command.

I just got an error in my client application that uses a wcf method to extract some data from a SQL Server database. The error was:

“Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding”

Obviously it’s a timeout issue due to complexity of the query. To fix this you would need to take alook at your binding settings in the App.config file. Typically there are a few timeout settings that you can modify there. Look under section and locate and then . You should see the settings for your timeouts like below:

The sendTimeout shows how long the client will wait till it gets the response from WCF service. The format is hours:minutes:seconds. It shows the total time of sending a message through your service including receiving the reply message in a wcf request-reply case.
The closeTimeout shows how long you will wait before you close the connection before an exception is thrown. Usually this disposes the client WCF proxy.

In my case, I just increased the sendTimeout and closeTimeout and the problem was gone.

In C#, unlike value types (int, double, struct, DateTime,..) we cannot use operator “==” for objects to check the equality. In order to check the equality of two reference variables, we need to implement the interface: IEquatable. This interface can be well used for generic collection objects like Dictionary<TKey, TValue> or List<T>

This interface is used when you want to implement your own “Equals” method for your object. Once you implement it, it will be used when you are checking for equality in methods like Contains, IndexOf, LastIndexOf or Remove.