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 ...
| Sharepoint Microsoft sharepoint portal server development, administration and related discussions |
![]() |
| | LinkBack | Thread Tools |
|
#1
| |||
| |||
| 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
| |||
| |||
| 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
| |||
| |||
| 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 |
|
#4
| |||
| |||
| 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 |
![]() |
| Thread Tools | |
| |
| ||||
| 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 |



