Tuesday 2 September 2014

Adding user in SharePoint group programmatically

Below is the code to add user in SharePoint group programmatically:


 using (SPSite site = new SPSite(Respective Site URL))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    try
                    {
                        SPUser requiredUser = web.EnsureUser("domainname\\username");

                        if (requiredUser != null)
                        {
                            SPGroup requiredGroup = web.Groups["groupName"];
                            if (requiredGroup != null)
                                requiredGroup.AddUser(requiredUser);
                        }
                   
                    }
                    catch (Exception ex)
                    {
                     
                    }                 
                }
            }

Monday 1 September 2014

Error occurred in deployment step 'Retract Solution': Object reference not set to an instance of an object.

Today while deploying a custom solution on our development server using Visual Studio 2012, I received below error in Visual Studio: 
"Error occurred in deployment step 'Retract Solution': Object reference not set to an instance of an object."

This was working well till day before and suddenly it started to throw same error again and again.
Then I went to retract same solution through Central Administration, and it shown me actual error that was happening.

The SharePoint_Config log file got full. After shrinking the log file, solution got deployed without any error.

Related Posts Plugin for WordPress, Blogger...