The code below will terminate all running workflow instances for a give SPListItem.
The order in which fields are displayed in the New, Edit, and Display forms for a list item is determined by the FieldLinks order of its content type.
The SPFieldLinkCollection has a handy Reorder method that we can use to set the order of the fields, using their internal names.
The script below does this through PowerShell:
Getting Checked out Files
<Where> <IsNotNull> <FieldRef Name='CheckoutUser' /> </IsNotNull> </Where>
<Where> <Eq> <FieldRef Name='_Level' /> <Value Type='Integer'>255</Value> </Eq> </Where>
Getting Published Files
<Where> <Eq> <FieldRef Name='_Level' /> <Value Type='Integer'>1</Value> </Eq> </Where>
Getting Checked-in Files
<Where> <Eq> <FieldRef Name='_Level' /> <Value Type='Integer'>2</Value> </Eq> </Where>
Getting Files Only (i.e. excluding Folders)
<Where> <Eq> <FieldRef Name='FSObjType' /> <Value Type='Integer'>0</Value> </Eq> </Where>
Getting Folders Only (including Document Sets)
<Where> <Eq> <FieldRef Name='FSObjType' /> <Value Type='Integer'>1</Value> </Eq> </Where>
<Where> <Eq> <FieldRef Name='WorkflowLink' /> <Value Type='URL'>/subsite/listname/item-url.docx</Value> </Eq> </Where>
Note that you must use a server relative URL when querying against a URL field.
In general, I try to avoid using .ToString() as much as possible. Instead I prefer to just rely on the automatic string conversion that is done in string concatenations, or in the string.Format() methods.
Consider the simple code example below.
Say you have a drop down list defined as a select tag:
<select id="dropdown"> <option value="1">One</option> <option value="2">Two</option> <option value="3" selected>Three</option> </select>
You can very easily disable the drop down list with jQuery by adding a disabled property to the tag.
However, in doing that, the selected value of the drop down list is no longer posted back on a form submit. And some systems (such as SharePoint) may then persist the default value when saving changes, which in the example above is “1” instead of the selected “3”.
So instead of a straight forward disable, we’re forced to do some extra work to make sure the control remains disabled on the front end to the user, but still posts back the corrected selected value to the back end.
When renaming document sets in code, it needs to be done in the same way as renaming folders.
You can’t just change the Title, you’ll need to change the Name value as well, otherwise the document set / folder name remains the same.
When trying to update a workflow task item in code, you may get the error “This task is currently locked by a running workflow and cannot be edited.”
This error gets thrown because the ows_WorkflowVersion of the task list item has been set to 512.
There may be a good reason it’s set to locked (i.e. currently being updated) but it you really really want to still update the task, you can override the flag.