none
Tasks Sync from Project 2007 to SharePoint 2010 : Issue in Assigned To field. RRS feed

  • Question

  • Hello,

     

    I have developed Add in "Sync Project 2007 MPP Task to SharePoint 2010 Task List". I am able to save task detail for following fields into SharePoint 2010.

    Task fields: Title,StartDate, EndDate, DurationInday, Perecentage Complete and Actual Finish.

     

    Issue: Now I want to insert information from Project 2007 MPP field Resource Name into SharePoint 2010 Tasks list fields Assigned To.

    I have tried following Code:

    SPFieldUserValueCollection resouceCollection = new SPFieldUserValueCollection();

    string[] resourceName;

    resourceName = ResourceName.Split(',');

    if (resourceName.Count() > 0)

    {

    foreach (string rname in resourceName)

    {

    SPUser userResource = EnsureUserFromSPSite(_spHomeSite, rname);

    if (userResource != null)

    {

    SPFieldUserValue spFieldUserValueObject = new SPFieldUserValue(SPContext.Current.Web, userResource.ID, userResource.LoginName);

    resouceCollection.Add(spFieldUserValueObject);

     }

    }

    item["AssignTo"] = resouceCollection;

    }

     

    private SPUser EnsureUserFromSPSite(string _spHomeSite,string UserName)

            {

                SPUser resourceName = null;

                try

                {

                     SPSecurity.RunWithElevatedPrivileges(delegate()

                    {

                        using (SPSite oSite = new SPSite(_spHomeSite))

                        {

                            using (SPWeb oWeb = oSite.OpenWeb())

                            {

                                oWeb.AllowUnsafeUpdates = true;

                                resourceName = oWeb.EnsureUser(UserName);

                                oWeb.AllowUnsafeUpdates = false;

                            }

                        }

                    });

                }

                catch (System.Exception ex)

                {

                    throw;

                }

     

                return resourceName;

            }

     

     

    But while calling EnsureUserFromSPSite functionit giving “Default Membership Provider must be specified.” error

     

    Please help me with insertion of Resource Name in Assigned To field in SharePoint 2010.

    Thanks & Regards,

    Bhavin Sankhat



    Monday, June 25, 2012 10:01 AM

Answers

  • Resolved issue using client object Model. Successfully able to add task into SharePoint Task List.

     private void AddTaskToSPUsing(string siteUrl, string TaskList, string title, DateTime startDate, DateTime enddate, int DurationInday, string ResourceName, double percent_complete, DateTime actual_finish)

            {
                string[] resourceName;
                NetworkCredential credentials = new NetworkCredential("UserName", "Pass", "DomainName");
                try
                {
                    using (ClientContext clientContext = new ClientContext(siteUrl))
                    {
                        clientContext.Credentials = credentials;
                        clientContext.ExecutingWebRequest += new EventHandler<WebRequestEventArgs>(clientContext_ExecutingWebRequest);
                        Microsoft.SharePoint.Client.List oList = clientContext.Web.Lists.GetByTitle(TaskList);
                        resourceName = ResourceName.Split(',');

                        if (resourceName.Count() > 0)
                        {
                            foreach (string rname in resourceName)
                            {
                                ListItemCreationInformation listCreationInformation = new ListItemCreationInformation();
                                ListItem oListItem = oList.AddItem(listCreationInformation);
                                oListItem["Title"] = title;
                                oListItem["StartDate"] = startDate;
                                oListItem["_EndDate"] = enddate;
                                oListItem["DurationInday"] = DurationInday;
                                oListItem["ResourceName"] = ResourceName;
                                oListItem["PercentComplete"] = percent_complete;
                                oListItem["ActualFinish"] = actual_finish;
                                User us = ClientAuth(rname, siteUrl);
                                if (us != null)
                                {
                                    oListItem["AssignedTo"] = us.Id;
                                }
                                oListItem.Update();
                                clientContext.ExecuteQuery();
                            }
                        }
                    }
                }
                catch (System.Exception)
                {

                    throw;
                }

            }

    public User ClientAuth(string userName, string _spHomeSite)
            {
                  NetworkCredential credentials = new NetworkCredential("UserName", "Pass", "DomainName");
                User us;
                try
                {
                    using (ClientContext clientContext = new ClientContext(_spHomeSite))
                    {
                        clientContext.Credentials = credentials;
                        clientContext.ExecutingWebRequest += new EventHandler<WebRequestEventArgs>(clientContext_ExecutingWebRequest);
                        Web site = clientContext.Web;
                        clientContext.Load(site);
                        us = site.EnsureUser(userName);
                        clientContext.Load(us);
                        clientContext.ExecuteQuery();
                    }
                }
                catch (System.Exception)
                {
                    us = null;
                }

                return us;
            }

    Tuesday, June 26, 2012 8:32 AM