.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Using SPListItem.SystemUpdate

Posted By:      Posted Date: October 19, 2010    Points: 0   Category :SharePoint

I am using SPListItem.systemUpdate in a timerjob to update a documents properties within a list. When this is invoked the properties are correctly update, however the Approval Status is set to Draft.

Is there anyway of ensuring this approval status is set to approved as not all users can see a draft version?


Thanks in advance

View Complete Post

More Related Resource Links

Update Vs SystemUpdate

Many of you might noticed that share point ListItem has Update() method as well as SystemUpdate().

What is the difference between these two methods and why MOSS has two different APIs for updating an ListItem

How to Add a Version History of SPlistItem ?


Now , I import the splistitem data from a list to another list, but  the listitem's version history disappear, Also I can get the splistitem's Version . what should I do to add each Version History of  the   listItem ???

Can you give me some code ?

Help me ,




Edit SPListItem



I want to edit the content of list items in a Sharepoint list programmatically (C#).
The properties of the items contain of a column  named "project" which is a MultiChoice column.

I want to set the projects programmatically for the items.
Can anybody help me?


SPListItem Title URL property??

Hello, I am not exactly sure how to express this query. I have a list with items, the items have titles. When the title link is clicked, it displays a form. I would like to change this behavior and have it act like a URL to a site page. I have searched for the morning and day and have come up with this: web.AllowUnsafeUpdates = true; SPListItemCollection itemCollection = list.Items; item = itemCollection.Add(f.ServerRelativeUrl,SPFileSystemObjectType.File, "Name of item"); item["Title"] = "Name of item"; SPFieldUrlValue url_value = new SPFieldUrlValue(item["Title"].ToString()); url_value.Url = "http://www.google.com"; item[SPBuiltInFieldId.Title] = url_value; item.Update(); web.AllowUnsafeUpdates = false; Now, that is what many blogs, examples have as 'the way", however when this runs the item title is: http://www.google.com , http://www.google.com and when clicked does not go to google...but the form again.   Do I need a custome content type to express the Title as a URL?  Or does it have this property out of the box? So frustrated, maxwell

Rename SPListItem file with extention

Hi guys,   I'm working with a simple workflow that is fired when a item has been added. workflow code is currenlty very simple..     Suppose that I upload original.doc. Following code will rename it to renamed.doc. I cannot find any way to rename "doc" extention to sth else.   Any ideas ? private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e) { workflowProperties.Item["Name"] = "renamed.xml"; // .xml extention is ignored! workflowProperties.Item.SystemUpdate(); }  

Adding SPListItem to a SPList with External Data Column

I used SharePoint 2010's BCS to create an external content type. I added a list column of the type "External Data" to a custom list. 1. When I add an Item through the SharePoint interface, the external data field is displayed correctly in the view. 2. I add the item using the following code:   SPListItem newItem = customList.Items.Add(); newItem["Title" ] = "Test" ; newItem["ExternalDataColumnTest" ] = "1111" ; newItem.Update();   Now, When i go to the list, i can see the new item, but the External Data Column is empty in the view. When I use the ECB action "View Item", i can see that the primary key of my external data type item was saved. When I use the ECB action "Edit Item", the external data column field is empty. When I compare the item I added with the one I added through code in the VS2010 debugger, they hold exactly the same value ("1111" in example above). Any advice would be greatly appreciated.  

Extract document for a SPListItem from a Document Library using the Object Model


WSS 3.0

I want to use the object model to extract the document from a Document Library. I am doing a foreach(SPListItem item in docLib).

How can I use SPListItem to get the document for that item?

Updating SPListItem fields in a timer job



I've created and registered an SPJobDefinition and what it does is that it runs through some list items on all sites and does some cleanup. On these lists there is a field called Last Run and I update these field with a timestamp... or at least I thought I did :-) When I step through the debugger it works, but when I don't the field never gets updated...

The proceedure is this:

  1. Checkout the file in the document library
  2. Overwriting the file with a newer version
  3. Update the file's item field Last Run using this code:
file.Item["Last Run"] = DateTime.Now.ToString("ddddd, MMMM dd, yyyy hh:mm:ss tt");

4. Checkin the file

5. Run file.Update()

Any idea why this works when I step through the code, but doesn't otherwise?



Random error during update splistitem


Sometimes I get an error message when I update a splistitem:

Microsoft.SharePoint.SPException: Cannot complete this action. Contact your administrator. ---> System.Runtime.InteropServices.COMException (0x81070518): Cannot complete this action. Contact your administrator.
   at Microsoft.SharePoint.Library.SPRequestInternalClass.AddOrUpdateItem(String bstrUrl, String bstrListName, Boolean bAdd, Boolean bSystemUpdate, Boolean bPreserveItemVersion, Boolean bUpdateNoVersion, Int32& plID, String& pbstrGuid, Guid pbstrNewDocId, Boolean bHasNewDocId, String bstrVersion, Object& pvarAttachmentNames, Object& pvarAttachmentContents, Object& pvarProperties, Boolean bCheckOut, Boolean bCheckin, Boolean bMigration, Boolean bPublish)
   at Microsoft.SharePoint.Library.SPRequest.AddOrUpdateItem(String bstrUrl, String bstrListName, Boolean bAdd, Boolean bSystemUpdate, Boolean bPreserveItemVersion, Boolean bUpdateNoVersion, Int32& plID, String& pbstrGuid, Guid pbstrNewDocId, Boolean bHasNewDocId, String bstrVersion, Object& pvarAttachmentNames, Object& pvarAttachmentContents, Object& pvarProperties, Boolean bCheckOut, Boolean bC

SPListItem.Update fails inside a TransactionScope


I've added a CodeActivity to a Sequential Workflow, and placed it inside a TransactionScope activity.

In my code activity I am calling the Update() method on an SPListItem. When that line hits I get the following error:

Unable to cast COM object of type 'Microsoft.SharePoint.Library.SPRequestInternalClass' to interface type 'Microsoft.SharePoint.Library.ISPRequest'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{BDEADF28-C265-11D0-BCED-00A0C90AB50F}' failed due to the following error: Bad variable type. (Exception from HRESULT: 0x80020008 (DISP_E_BADVARTYPE)).

Does anyone have any idea why this is happening?

Martin Hatch
MCPD .Net Web Development
MCTS WSS 3.0 | MOSS 2007
Visit my Blog - www.martinhatch.com

Value does not fall within the expected range? Using Internal Field Name returned from SPListItem Fi

Here's the code.

myDocument is an SPListItem.
string fieldName = "Document Category";
string internalFieldName = myDocument.Fields[fieldName].InternalName.ToString();
Type myType = myDocument[internalFieldName].GetType();
internalFieldName gets the value "Document_x0020_Category"

But myType = myDocument[internalFieldName].GetType() throws an exception error of "Value does not fall within the expected range"??

If the fieldname is found in the fields collection, and returns the internal field name, why would using the internal field name as an indexer into the document throw an exception?

myDocument has a value in field "Document Category" when I view properties on the document in the document library! I am expecting the field type to be of

SPListItem "Start Time" for recurring events when building a task reminder Timer job.


I have a timer job that looks at maintenance events (calendar list) planned 5 days in the future and moves them to the current todo list. It then marks that maintenance item as copied so it is not double copied to the current todo list.

This works good for single event maintenance items but not for routine or recurring maintenance items. The reason is the recurring events have a "start time" of the first event so after the first one gets moved the rest are all interpreted as being in the past, since (I think) the recurring events start time is generated as an offset of the original event at runtime. How would I get a collection of ALL the Event items that are 5 days out (single and recurring) within a timer job.




Expanded recurrence items cannot be updated

Invalid SPListItem. The SPListItem provided is not compatible with a Publishing Page.


I am trying to display .swf [flash] in a publishing web part page. I am able to see my flash after applying the properties to web part.

When I am trying to check in I get:

"Invalid SPListItem. The SPListItem provided is not compatible with a Publishing Page."

Log says:

System.ArgumentException: Invalid SPListItem. The SPListItem provided is not compatible with a Publishing Page.    at Microsoft.SharePoint.Publishing.PublishingPage.GetPublishingPage(SPListItem sourceListItem)     at Microsoft.SharePoint.Publishing.Internal.WebControls.PublishingPageStateControl.RaisePostBackEventForPageRouting(String eventArgument, SPRibbonCommandHandler control, RaisePostBackEventDelegate raisePostBackEventDelegate)     at Microsoft.SharePoint.Publishing.Internal.WebControls.PublishingPageCheckinHandler.RaisePostBackEvent(String eventArgument)     at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)     at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Please suggest.



Using SPListItem.Approve


I am using the following code and it is failing because of a lack of permissions when I attempt to Approve the document.

If I run the same code (minus the ElevatedPrivileges under Sharepoint Admin...the code works correctly)....any ideas guys ?


                        SPContext currentContext1 = SPContext.Current;
                        SPWeb currentWeb1 = currentContext1.Web;
                        SPList submittedContent1 = currentWeb1.Lists["Listname1"];
                        SPListItem document1 = submittedContent1.GetItemById(ID);


SPListItem Update() does not work from list.Items collection.


Hi All,

Not working code:

using System;
using Microsoft.SharePoint;

namespace ConsoleApplication3

class Program

How to get the Task (SPListItem) in the OnTaskCreated activity?



How to get the Task ( as SPListItem object) in the OnTaskCreated activity. The taskId used when creating the task isn't the uniqueId of the Task so using it in the


 _workflowProperties.TaskList.GetItemByUniqueId(Guid taskId)


 won't give me the SpListItem i need. The final gol is to set user permissions to the task.




SPListItem.CopyTo method fails when copying to some sub-sites, but not others




A custom workflow has been developed that copies pages from a top-level site to sub-sites. The pages are copied into a specific folder within the Pages Library of the sub-sites.


This workflow has been installed in 3 site collections and it works without any problems in 2 of these. In the third site collection, we achieve mixed results where the pages are copied successfully to some sub-sites, but not to others.


An exception is raised a few levels deep within the SPListItem.CopyTo metho

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend