Sharepoint Content type with lookup field

content-typelookupsharepointsharepoint-2010

i am trying to create a lookup inside a Content type.

Here is what i wrote in my column definitions.

<Field ID="{B8AC7868-A34D-4F2E-A259-BE9EA6EA578A}" 
     Name="NewsCategory" 
     Required="FALSE"
     DisplayName="NewsCategory" 
     Type="Lookup" 
     List="ListCategory"
     FieldRef="Title"
     ShowField="Title"
     Group="MyCustomGroup"/>

Here is what i wrote inside the Content Type i want to attach the said column too.

<FieldRef ID="{B8AC7868-A34D-4F2E-A259-BE9EA6EA578A}"
Name="NewsCategory"DisplayName="NewsCategory" Required="FALSE" />

Then i went on the site and created a list called "ListCategory" and it has a Title and thats it.

For some reason i have having alot of trouble deploying, but when i finally get it to deploy i get an error while creating a page with the said content type. Is my definition good ?

Thanks for any help !!

Best Answer

You need 2 files: VS > SP 2010 project > Add item > Content Type has this code:

    <?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <!-- Parent ContentType: Todos los Documentos CiaContentTypes\00TodosLosDocumentos) (0x01010038bd2600185840119dfa3fe0c7b8b3d9) -->
  <ContentType ID="0x01010038bd2600185840119dfa3fe0c7b8b3d9005146d39cd2cf4d51b7ee2fc54bbe3215"
               Name="Archivo Historico"
               Group="05 Gestión Operativa"
               Description="Archivo Histórico"
               Inherits="TRUE"
               Version="0">
    <FieldRefs>
      <FieldRef ID="{709E337A-3FEF-4C96-8B00-8CF6723C969A}" Name="Empty" DisplayName="Empty"/>
    </FieldRefs>
  </ContentType>
</Elements>

Second file: Add item > SP 2010 > Empty element has this code:

    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Field
    Type="Text"
    Description="Breve Descricpción del documento"
    Required="TRUE"
    MaxLength="255"
    Group="Archivo Histórico"
    ID="{709E337A-3FEF-4C96-8B00-8CF6723C969A}"
    StaticName="Empty" Name="Empty" DisplayName="Empty">
  </Field>

</Elements>

Good luck, ALEX

Create unique GUID

Content Type IDs

Creating Content Types for SharePoint 2010 in Visual Studio 2010