Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3236940
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:40:48+00:00 2026-05-17T17:40:48+00:00

As the title says: in sharepoint 2010 i need to programmatically create a view

  • 0

As the title says: in sharepoint 2010 i need to programmatically create a view which lets me filter on the items on a list (a list of person). In this person list i have a lookup field which refers to another list (projects): i need to show only the people that work on a determinated project (passed as a string)

I have created an example view using this code:

class Program
    {
        static void Main(string[] args)
        {
            using (SPSite site = new SPSite("http://dev_seventeen:999"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPList books = web.Lists["Books"];
                    StringCollection fields = new StringCollection();
                    fields.Add("Title");
                    fields.Add("Publisher");
                    fields.Add("Autore");
                    var query = new XElement("Where",
                                    new XElement("Eq",
                                        new XElement("FieldRef", new XAttribute("Name", "Publisher")),
                                        new XElement("Value", new XAttribute("Type", "Choice"), "Alpha")
                                        )
                                    ).ToString(SaveOptions.DisableFormatting);

                    SPView view = books.Views.Add("TestView",
                        fields,
                        query,
                        100,
                        false,
                        false,
                        Microsoft.SharePoint.SPViewCollection.SPViewType.Html,
                        false
                        );
                    Console.WriteLine(query);
                    Console.ReadLine();
                }
            }
        }
    }

It filters a list named “Books” on a choice type field named “Publisher”, looking for all books published by “Alpha”

What i need to know is how to filter on a lookup field instead of a chioce one, because if i just put “Lookup” instead of “Choice” in the query it doesn’t work =(

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T17:40:49+00:00Added an answer on May 17, 2026 at 5:40 pm

    Can you use LookupID as type? That would make sure you only have one match. Check the following pages for Lookup fields, CAML & LINQ:

    • LINQ to CAML
    • Lookup fields inside out
    • Using CAML to query Sharepoint lists
      over Lookup fields
    • CAML – Query Lookup Field by ID; not
      by Value
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As the title says, i need a way to programmatically edit an existing view
As title says, i need to get this information regarding the screen state. I
As title says, I have a list of words, Like stopWords = [the, and,
As title says, i know that new throws an exception which can be caught,
As title says. I want to perform and order by on a list -
As title says for some purpose I need to get the size of request/response
As title says need to convert a Zip file to text file , no
As the title says, I'm trying to do something like this: public abstract class
As title says, is there any way to pull something like this up?: std::set<boost::shared_ptr<MyClass>>
As title says I need help with onchange. I have select tag,and I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.