Thursday, August 20, 2009

SharePoint Cannot complete this action error

When i am trying to count the CheckedOut items from SharePoint Document Library using c# code in visual studio as shown below

SPSite mysite = new SPSite("http://servername:portnumber");
SPWeb myWeb = mysite.OpenWeb();
myWeb.AllowUnsafeUpdates = true;
SPList Document = myWeb.Lists["Shared Documents"];
SPQuery query = new SPQuery();
query.Query ="<Where><IsNotNull><FieldRef Name='CheckoutUser' /></IsNotNull></Where>";
SPListItemCollection checkedOutItems= Document.GetItems(query);
Response.Write(checkedOutItems.Count);

I got the following error:
System.Runtime.InteropServices.COMException: Cannot complete this action

Resolution:

We need add the tag "<identity impersonate='true'/>" tag in the web.config file of the project in the visual studio.
This is because the ASP.NET doesnt allows you to read the outside documents i.e the documents(folders) are not in ASP.NET Application.So we need to keep impersonate = true in web.config file.

Hopes this helps you....

1 comment:

electronic signature said...

i am also getting the error
System.Runtime.InteropServices.COMException: Cannot complete this action
i have added the tag "" tag in the web.config but it did not solved the problem either.Can you guess why it could be