Skip to main content
deleted 3 characters in body
Source Link
Phil Greer
  • 2.3k
  • 9
  • 21
  • 23

I have a custom Document Library that has a custom content type which is an extension of a Folder (just adding some more fields). I'm trying to, in code, add a new item of this content type to the library. But aI get the error:

To add an item to a document library, use SPFileCollection.Add() 

To add an item to a document library, use SPFileCollection.Add()

But what I am adding is not a file, and all the overloads for that method require some kind of file stream or object. I've tried:

SPListItem newCustomFolder = docLibrary.Folders.Add();
SPListItem newCustomFolder = docLibrary.AddItem();
SPListItem newCustomFolder = docLibrary.Items.Add();

And trying to declare it as SPFolder doesn't match the return of the above functions nor does accept setting fields.

How do I do this?

I have a custom Document Library that has a custom content type which is an extension of a Folder (just adding some more fields). I'm trying to, in code, add a new item of this content type to the library. But a get the error:

To add an item to a document library, use SPFileCollection.Add() 

But what I am adding is not a file, and all the overloads for that method require some kind of file stream or object. I've tried:

SPListItem newCustomFolder = docLibrary.Folders.Add();
SPListItem newCustomFolder = docLibrary.AddItem();
SPListItem newCustomFolder = docLibrary.Items.Add();

And trying to declare it as SPFolder doesn't match the return of the above functions nor does accept setting fields.

How do I do this?

I have a custom Document Library that has a custom content type which is an extension of a Folder (just adding some more fields). I'm trying to, in code, add a new item of this content type to the library. But I get the error:

To add an item to a document library, use SPFileCollection.Add()

But what I am adding is not a file, and all the overloads for that method require some kind of file stream or object. I've tried:

SPListItem newCustomFolder = docLibrary.Folders.Add();
SPListItem newCustomFolder = docLibrary.AddItem();
SPListItem newCustomFolder = docLibrary.Items.Add();

And trying to declare it as SPFolder doesn't match the return of the above functions nor does accept setting fields.

How do I do this?

Source Link
HamHamJ
  • 395
  • 3
  • 15

Add custom folder programatically to Document Library

I have a custom Document Library that has a custom content type which is an extension of a Folder (just adding some more fields). I'm trying to, in code, add a new item of this content type to the library. But a get the error:

To add an item to a document library, use SPFileCollection.Add() 

But what I am adding is not a file, and all the overloads for that method require some kind of file stream or object. I've tried:

SPListItem newCustomFolder = docLibrary.Folders.Add();
SPListItem newCustomFolder = docLibrary.AddItem();
SPListItem newCustomFolder = docLibrary.Items.Add();

And trying to declare it as SPFolder doesn't match the return of the above functions nor does accept setting fields.

How do I do this?