locked
problem in updating group of office communication user RRS feed

  • Question

  •  

    public bool UpdateContactGroup(string oldgroupName,string newGroupName, string userInstanceID)
            {
                bool output;
                this._contactGroupClass = new ManagementClass(_defaultNameSpace, "MSFT_SIPESUserContactGroupData",
                    null);
                 string query = "SELECT * FROM MSFT_SIPESUserContactGroupData "
                    + "WHERE (UserInstanceID = '" + userInstanceID + "')";
                           ManagementObjectSearcher GroupSearcher =
                   new ManagementObjectSearcher(_defaultNameSpace, query);

     ManagementObjectCollection groups = GroupSearcher.Get();
                try
                {
                    foreach (ManagementObject group in groups)
                    {
                        if ((string)group["Name"] == oldgroupName)
                        {
                            ManagementObject ContactGroup = _contactGroupClass.CreateInstance();
                             ContactGroup["Name"] = newGroupName;
                            PutOptions options = new PutOptions();
                            options.Type = PutType.UpdateOrCreate;
                            try
                            {


                                // group.Put(options);
                                ContactGroup.Put(options);
                                GroupSearcher.Dispose();
                                ContactGroup.Dispose();
                                groups.Dispose();
                                return true;
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.ToString());
                                return false;
                            }
                        }

                    }
                    return true;
                }
                catch (System.Runtime.InteropServices.COMException ex)
                {
                    return false;
                    // MessageBox.Show(ex.Message);
                }
             
              

            }

     contactgroup.put(options)  this method commits changes and it should update group ,but it didn't work.

    so please,help me to solve this problem.

    Wednesday, October 31, 2007 1:27 PM