Objectmix
Tags Register Mark Forums Read

Create List ContentType programmatically : Sharepoint

This is a discussion on Create List ContentType programmatically within the Sharepoint forums in Microsoft Tools category; Hi, In WSS 3.0 / Moss 2007 I want to programmatically create a list level (not site level) content type using list level (and again not site level) columns. Adding the content type to a list seems straight forward the difficulty seems to be adding a field/column to the contentType. Below is the code I tried. The code gives me a System.ArgumentNullException error stating: {"Value cannot be null.\r\nParameter name: g"} on the line. SPFieldLink fieldLink = new SPFieldLink(field); Thanks for your help, NickW SPSite site = new SPSite( http://TestSite/); SPWeb web = site.OpenWeb(); web.AllowUnsafeUpdates = true; //Create new doc library ...


Object Mix > Microsoft Tools > Sharepoint > Create List ContentType programmatically

Sharepoint Microsoft sharepoint portal server development, administration and related discussions

Reply

 

LinkBack Thread Tools
  #1  
Old 08-07-2007, 05:30 AM
Junior Member
 
Join Date: Nov 2009
Posts: 0
Application Development is on a distinguished road
Default Create List ContentType programmatically

Hi,
In WSS 3.0 / Moss 2007 I want to programmatically create a list level (not
site level) content type using list level (and again not site level)
columns.
Adding the content type to a list seems straight forward the difficulty
seems to be adding a field/column to the contentType.
Below is the code I tried. The code gives me a System.ArgumentNullException
error stating: {"Value cannot be null.\r\nParameter name: g"} on the line.
SPFieldLink fieldLink = new SPFieldLink(field);

Thanks for your help,
NickW
SPSite site = new SPSite(http://TestSite/);

SPWeb web = site.OpenWeb();

web.AllowUnsafeUpdates = true;

//Create new doc library

SPListTemplate listTemplate = web.ListTemplates["Document Library"];

web.Lists.Add(selectedMaster.Reference, "Document Library", listTemplate);

SPList list = web.Lists["TestDocLib"];

list.ContentTypesEnabled = true;

//Create Content Type

SPContentType documentContentType = web.AvailableContentTypes["Document"];

SPContentType newContentType = new SPContentType(documentContentType,
web.ContentTypes, selectedMaster.Reference);


SPField field = new SPField(newContentType.Fields,"Text","Test");

SPFieldLink fieldLink = new SPFieldLink(field);

newContentType.FieldLinks.Add(fieldLink);

newContentType.Update(false);

list.ContentTypes.Add(newContentType);






  #2  
Old 04-23-2008, 03:09 PM
Junior Member
 
Join Date: Nov 2009
Posts: 0
Application Development is on a distinguished road
Default did you get an answer to your error (value cannot benull)?

I am receiving the same error trying to add a field to the newly created document library.

Did you figure out why?

Any clues would be very helpful to me

Thanks
  #3  
Old 02-08-2010, 07:07 AM
Member
 
Join Date: Feb 2010
Posts: 49
elizas is on a distinguished road
Default Re: Create List ContentType programmatically

You can think of a SharePoint List somewhat similar to a table present within a Database. As tables consist of different columns, a SharePoint List also comprises of different columns / fields and these fields can indeed have different attributes associated to it (like "Required field check", "Max Length", "Display Formats", etc).
We can use SharePoint API to create these fields and associate the corresponding attributes programmatically within an existing List.

thanks
__________________
Cheers,
Eliza
  #4  
Old 06-22-2010, 08:42 AM
Junior Member
 
Join Date: Dec 2009
Posts: 8
bijayani is on a distinguished road
Default Re: Create List ContentType programmatically

Often there is a requirement of creating Lists within a SharePoint website programmatically using API calls. Described below are 2 different methods of achieving the same using C#.Net as the programming language.

In the first approach, a SharePoint List gets created using an existing custom List Template present within the List Template Gallery. This approach helps replicate a list exactly in the same structure as of the list from which the custom list template was generated.

In the second approach, a blank SharePoint List gets generated depending on the List Template Type specified during the creation process. This approach can be used to create blank lists of type Announcements, Contacts, Discussion Board, Document Library, Events, Links, Meetings, Picture Library, Survey, Tasks, etc.

Thanks,
Bijayani
Reply

Thread Tools


Similar Threads

Thread Thread Starter Forum Replies Last Post
Programmatically create SharedServiceProvider usenet Sharepoint 0 11-27-2007 01:43 AM
How do I programmatically create and save an empty project? usenet labview 1 08-08-2007 10:40 PM
Programmatically create a task usenet Microsoft Exchange 1 09-29-2004 05:58 PM
Re: Can ADO.NET create a table in the database programmatically without executing CREATE TABLE sql statement? usenet DOTNET 0 08-30-2004 09:56 AM
How to programmatically create a user in Mercury usenet Pegasus 0 03-04-2004 05:32 PM


All times are GMT -5. The time now is 12:40 AM.

Managed by Infnx Pvt Ltd.