I am using PowerShell to add 100 items which need to be of a specific ContentType.

(requirement) Test my custom events receiver using powershell. The test is to create a list with a custom content type and then add 100 items of that content type.

(background) I am trying to rule out the reasons for a strange behaviour in list workflows. Support team claims it is caused by our custom AddItem event, which I doubt since the receiver works fine on other lists. My addItem custom event receiver uses the ContentTypeID to initiate a corresponding workflow from another configuration list.

(previous searches) This thread gives a different answer to my requirement, I don't want to change or update an-already-added item.

(question) How do I add an item with my content type ID, or create the object with certain CT-ID before adding it because I want to test the "AddItem" event receiver. I created te following pseudocode to clarify what I am looking for:

get CSV "c:\file.csv"
connect to SPList "MyList"
for( file.Item Count )
 Create Item object i;
 set object i.ContentID = 0x001ETC #this!
 MyList.AddItem(object i);
End loop & close connection

The action my colleague suggested was to put the content type that I want to use as the default content type from list settings.

It is not exactly how I wanted it but it partially solved the question.

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.