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

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

Using SPListItem.Approve

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

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);


View Complete Post

More Related Resource Links

Approve/Reject a document using Sharepoint web services


Is there a way to approve / reject a file that has been published on sharepoint 2007 using web services only?

Say there is a document 'A.xls' that was published as a major version by the author. I want the admin to be able to approve/reject it from a site outside the Sharepoint application. I know there is a workflow involved in this, but is there a web service that exposes the functionalities attributed to this workflow?


Is there something else I need to 'check' to approve multiple documents


I can't seem to approve multiple documents even when following the proper procedure.

I'm using MOSS, with an internet/Publishing site.  I go to site actions >> manage Content, check the checkboxes next to the items I need approved/checked in (they all have the same 'status' like draft, or pending), I click either approve or check in/publish depending on what I'm trying to do, and the only item that gets approved is the last item I checked. 

There is a workflow attached that when I click approve, I'm brought to the approval workflow page to add approvers and such, but it only lists one item for approval.

Anyone have any idea why that is, or has anyone experienced this before? 

Please heeeeeeeeeeeelp.

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?


reject author of the item to approve

hi, how can i hide the possebility that an author of an item can change the approval status. i want that only users who can approve items to approve items and not also the author itself. and how can i set "requires approval" as a required field? thnx

Task doesnt have the approve button

Finally I was able to start runing my workflow, it starts ok, and then it generates a task, but when I go to the task, it doesnt have the Approve or Reject buttons, What am I missing? www.sharepoint2010blogger.com Follow me on Twitter <<<

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

Problem setting up approve/reject settings in Absence Request and Vacation Management Template

Hi I have recently installed and set up the absence request and vacation management template in SharePoint Services 3.0 and all seems to be going reasonably well apart from one hitch. I have edited the setup workflow so that manager is sent an email on request, employee is sent an email on approval/rejection and payroll are sent an email on approval for their records. However, even though the Personal Vacation option in the Absence Type list is set to Yes for Approval Required, the workflow is automatically sending out the email to say their annual leave has been approved as soon as they request it. Has anyone come across this before or know where I may be going wrong? Thanks for any help you can give. Jo

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?

how to approve content inside web part?


We have a SharePoint site. There are a couple of web parts such as content editor web part on the home page.

People with contributor permission can modify the content of the web parts. Once the home checked in or checked in draft mode, the updated content will be showing up on the home page for all users.

Is it possible for those updated content has to be approved before users can view it?

Thanks in advance,



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?



How to make Discussion board to Approve/Reject ?


I created a subsite under site. I added a discussion board to sub site. Now I want make this discussion board to Approve /Reject. Right now anybody can see the posting on site. But I want a approve group should approve the post then only other can see the posting. How can we do that?

I am in MOSS 2007.

Thanks in advance.




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

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