I am trying to create a site column using via a console app. I would ultimately like to be able to migrate the site column and upgrade the same column via this app. To that end, I would need some control over the column's GUID. Is it possible to set GUID using the object model for a site column. I could not get a clue from the API: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfield_members.aspx


Yes, you can specify it. Example:

public static readonly Guid MyFieldId = 
  new Guid("{CC1E421C-29BE-4373-81D0-55D5D64B2E3D}");
public static readonly string MyFieldDefXml =
  "<Field ID=\"{CC1E421C-29BE-4373-81D0-55D5D64B2E3D}\"" +
  " Name=\"MyFieldName\" StaticName=\"MyFieldName\"" +
  " Type=\"Text\" DisplayName=\"My Field Name\"" +
  " Group=\"My Columns\" DisplaceOnUpgrade=\"TRUE\" />";

if (web.AvailableFields.Contains(MyFieldId) == false)

More information: http://msdn.microsoft.com/en-us/library/ff798370.aspx#Y209

  • 2
    Main point here is that you can only do it via XML - so either declaratively in a Feature, or as show here, using the AddFieldAsXml method. – James Love Jul 5 '11 at 20:30
  • That's right, James – Ashish Patel Jul 5 '11 at 20:34
  • Ashish, Thank you. I will try this out. But should the Field "ID" take the value of "MyFieldId" in the code above? – Sam Patrick Jul 5 '11 at 20:46
  • It takes only a valid GUID – Ashish Patel Jul 5 '11 at 20:49
  • @Ashish I meant to say: should CC1E421C-29BE-4373-81D0-55D5D64B2E3D be replace by 891B57CF-B826-4B0C-9EDF-8948C824D96F in the above code? I see that ID of MyFieldDefXml is not really being checked. Or may be I am missing something? – Sam Patrick Jul 5 '11 at 20:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.