Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm trying to create a task, in a VS 2010 workflow, and assign it to one of our domain users. This guy's not a site collection user, but I'm assuming that he'll be added to Sharepoint automatically. He's also located in another company branch, somewhere in South Africa. The code I'm using is something like

    private void CreateTask_MethodInvoking(object sender, EventArgs e)
    {
        TaskProps = new SPWorkflowTaskProperties();
        TaskId = Guid.NewGuid();

        TaskProps.AssignedTo = @"MYDOMAIN\username";
        TaskProps.Title = "Sample task";
    }

Once I deploy and run the workflow, the task gets created just fine, but the "Assigned To" field is blank. The event log shows that "User does not exist or is not unique."

Furthermore, if I create a task by hand, and put MYDOMAIN\username in the "Assigned To" field, it gets created with no problems, and the user gets imported to the site collection. After that, the workflow runs all right. Manually adding each of our 200+ domain users to the site collection is not an option, though. Suggestions?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

The assumption that the user is added to the site collection is not true. You cannot assign a task to a user who does not have permissiosn in the site collection, however you do not have to add every user manually.

  • do as MBSurf suggests and add the user in code
  • put all the users in a group in AD (if you don't already have one) and assign the group to the SharePoint site
  • Grant "All Authenticated Users" permissions to the task list so tasks can be assigned to anyone...
share|improve this answer

In MOSS, I would do something like below:

        SPUser spUser = null;

        try
        {
            // Attempt to get the user first
            spUser = userCollection[user];
        }
        catch (Exception)
        {
            // The User does not exist, so we need to add them
            userCollection.Add(user, string.Empty, user, string.Empty);
            spUser = userCollection[user];
        }

Then, I would save spUser in the Assigned To field.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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