0

I am using sharepoint 2010. We have a workflow activity builded in Visual Studio. This activity is copy or move a document to another library. The activity has a function where it is possible to run the activity as another user. These function is used and there is setted to a user which has full control on both libraries.

Does someone know where the error could be occured? And why do I got this error.

Below you see the code. I dont know where the error occurs in this method.

public SPFile Copy(string targetLibraryUrl, string comment)
        {
            SPFile result = null;

            var userToken = default(SPUserToken);
            if (string.IsNullOrEmpty(this.User))
            {
                userToken = this.Site.SystemAccount.UserToken;
            }
            else
            {
                userToken = this.Site.RootWeb.EnsureUser(this.User).UserToken;
            }

            Uri targetUri = new Uri(targetLibraryUrl, UriKind.RelativeOrAbsolute);

            string libUrl = targetLibraryUrl;
            if (targetUri.IsAbsoluteUri)
            {
                using (SPSite targetSite = new SPSite(targetLibraryUrl, userToken))
                {
                    if (SPSite.ValidateDomainCompatibility(_site.Url, targetLibraryUrl))
                    {
                        using (SPWeb targetWeb = targetSite.OpenWeb())
                        {
                            result = Copy(targetWeb, targetLibraryUrl, comment);
                        }
                    }
                }
            }
            else
            {
                using (SPSite targetSite = new SPSite(this.Site.ID, userToken))
                {
                    using (SPWeb targetWeb = targetSite.OpenWeb(targetLibraryUrl))
                    {
                        result = Copy(targetWeb, targetLibraryUrl, comment);
                    }
                }
            }


            return result;
        }

this is the error in the uls log:

Microsoft.SharePoint.SPException: User cannot be found.    
 at Microsoft.SharePoint.SPUserCollection.get_Item(String loginName)    
 at MyCompany.SPDActivities.Activities.CopyDocumentActivity.Execute(ActivityExecutionContext context)    
 at System.Workflow.ComponentModel.ActivityExecutor`1.Execute(T activity, ActivityExecutionContext executionContext)    
 at System.Workflow.ComponentModel.ActivityExecutor`1.Execute(Activity activity, ActivityExecutionContext executionContext)    
 at System.Workflow.ComponentModel.ActivityExecutorOperation.Run(IWorkflowCoreRuntime workflowCoreRuntime)    
 at System.Workflow.Runtime.Scheduler.Run()

UPDATE: the documents in this library are comming from emailing. So the end users are send an email to this library.

1 Answer 1

0

The problem probably is that the user is not available in the User Information List of the site. If you are copying documents from one site collection to another, make sure you use a SPWeb.EnsureUser(logonName) of the user fields before adding the document to the library.

You can find more information following this link

-Hope it helps

1
  • We know now that this problem occurs only at some email files. When we adding a new item everything is going ok.
    – Ola
    Commented Jul 24, 2014 at 9:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.