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.