SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Following is the code

SPList splist = web.Lists["MyList"];

var query = from SPListItem oItem in splist.Items.OfType<SPListItem>()
                            where !Convert.ToString(oItem["Status"]).Equals("Completed")
                            select oItem;

List<SPListItem> value = query.ToList<SPListItem>();

upto here working perfectly..

Now store value into viewstate getting following exception

ViewState.Add("Key", value);


System.Runtime.Serialization.SerializationException: Type 'Microsoft.SharePoint.SPListItem' in Assembly 'Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c' is not marked as serializable.


share|improve this question
The result of this query is SPListItems which are not serializable and cannot be added to the ViewState. This query may return a large amount of items and it is not recommended to save them in ViewState. What are you trying to achieve? Maybe there is a better way. – user3470 Dec 5 '12 at 5:55
i want get same linq query result during button click event bcz i don't trip to database(SPList) again. – Hitesh Chandegara Dec 5 '12 at 13:53
@hitz Do the query again on button click instead of saving in ViewState! – Arsalan Adam Khatri Dec 5 '12 at 14:11
You really should be running a CAML query. Using linq fetches all the items in the list before filtering them. If you have thousands of items, this will kill the server – Grooverinthesouth Dec 5 '12 at 16:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.