Creating media items using the API

There’s a real cool topic on SDN5-Forum about creating items using the API. A bunch of active chaps from the community are present there including Peter who provides a nice solution.

Make sure you also read the following reply written by myself on using the EditContext:

It’s not really recommended to use the EditContext as the code will run out of that scope when an exception occurs. I would rather suggest to use Item.Editing. The ItemEditing class allows you to use transaction-like methods such as AcceptChanges, BeginEdit, CancelEdit, EndEdit, RejectChanges, etc. This will improve the readability and flow of your code.

You might expect the using-contraint to be the best option, but it isn’t! Please be aware of this when you write production code.

One thought on “Creating media items using the API”

  1. I totally agree, the using() syntax in C# is way overrated. It seems that programmers, after getting garbage collection etc., has totally forgot the beauty of the try…finally and try…catch constructs 🙂

Comments are closed.