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

  • Home
  • SEARCH
  • 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 3316136
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:26:01+00:00 2026-05-17T22:26:01+00:00

For a project I am working on, I am trying to do the following

  • 0

For a project I am working on, I am trying to do the following thing.

There’s a Sharepoint 2010 environment, with a few Custom Lists created in Visual Studio. I am adding some fields to them using background code in the FeatureActivated function in the EventReceiver.

What I am doing there is adding a lookup field to the Sharepoint List, and setting the properties to allow it to lookup values from the other list I am adding to the Sharepoint Site.

However, I can’t find a function to add it to one of the views. I’ve tried modifying the Schema Xml, but I can’t seem to find a function to reinsert it to the List, and when using the Xml file from the View, I can’t seem to make it work.

Is there an easy way to programatically add a field to a view? This would help me out, since there seems to be no way to do this correctly.

This can also be solved if one could explain my other question I have.

I would like to know how one could make Lookup fields in the Schema XML file. I have a Custom Content Type, and Custom Fields, and I am currently trying to look up the Naam field in the Intermediairs List. (This one is also created when deploying this solution). When searching Google, it seems I have to use either a name / the GUID of a List Instance here, but I don’t know the GUID of the List Instance beforehand.

  <Field ID="{7CC49D9D-F6F5-4A4A-851F-3152AAAAB158}" Type="Lookup"
     List="Intermediairs" Name="IntermediairLookup" DisplayName="Intermediair"
     StaticName="IntermediairLookup" Group="Onboarding" ShowField="Naam" />

You should know that this code seems to work:

        SPWeb web = null;
        SPSite site = null;
        if (properties.Feature.Parent is SPWeb)
        {
            web = properties.Feature.Parent as SPWeb;
            site = web.Site;
        }
        if (properties.Feature.Parent is SPSite)
        {
            site = properties.Feature.Parent as SPSite;
            web = site.RootWeb;
        }
        web.AllowUnsafeUpdates = true;
        SPList changeList = web.Lists.TryGetList("Onboarding");
        SPList sourceList = web.Lists.TryGetList("Intermediairs");
        if (changeList != null && sourceList != null)
        {
            changeList.Fields.Delete("IntermediairLookup");
            var PrimaryColumnStr = changeList.Fields.AddLookup("Intermediair", sourceList.ID, true);
            var PrimaryColumn = changeList.Fields.GetFieldByInternalName(PrimaryColumnStr) as SPFieldLookup;
            PrimaryColumn.LookupField = sourceList.Fields["Naam"].InternalName;
            PrimaryColumn.Update();

        }

But yeah. I can’t figure out how to do it in XML form. Anyone has any ideas? A solution to either of the questions would solve my core issue.

Greetings,

Mats

EDIT: Well, the question has now been answered, thanks again!
One thing though. I would really like to know at some point how to do something like this in XML / CAML. Does anyone know how to do that? Anyone who’s still reading this thread?

  • 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-17T22:26:02+00:00Added an answer on May 17, 2026 at 10:26 pm

    Take a look at SPView.ViewFields

    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spview.viewfields.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While working on an existing project I suddenly got the following error when trying
The project I am working on were are trying to come up with a
I'm trying to automate the build of the project I'm working on. My ultimate
I'm trying to learn GNUMake for a small project I'm working on. So far,
I'm trying to create my own error window for the project I am working
I'm a Python novice, trying to use pyCurl. The project I am working on
I am working on an Actionscript 2 project - trying to use the XML
I am working on rails project and I am trying to get exceptions to
I am trying to setup tracd for the project I am currently working on.
I'm working on a PHP CMS like project and I'm trying to find out

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.