Monday, December 17, 2012

Error Type: Content database needs to be upgraded to support this operation


Users of SharePoint 2007 will have noticed that Microsoft had removed the Storage Management page when SharePoint 2010 was released.  Well, the good news is this has made a return in Service Pack 1 with a new look, showing the top 100 largest files or containers across a site collection.

I get to the Storage Metrics page by selecting Site Actions –> Site Settings and then choosing Storage  Metrics under the Site Collection heading.  But, before being able to use the new Storage Metrics feature I had to upgrade my content database.  The error message reads: “Content database needs to be upgraded to support this operation”.


I wasn’t entirely sure how to upgrade the content database, as I’d not done this before and drew a blank with Google, so after a bit of investigation on the server I discovered it took a few minutes using the following command:

C:\Program Files\Common Files\Microsoft Shared\Web ServerExtensions\14\bin\psconfig.exe –cmd upgrade

After successfully ran the command, now am able to see the results in metrics page.


If the configuration stall and got the error some thing like "The farm is being upgraded in the timer service process. The task is XX% completed."

Then have a look the follwoing post.


Reference is here.

Sunday, December 16, 2012

Error Type: The farm is being upgraded in the timer service process. The task is 10% completed.


I am trying to enable the Enterprise Features in SharePoint 2010.  I have turned on the setting in Central Admin and I have run the PSConfig.exe command to set the upgrade going.
The psconfig command runs but stalls at the following message "The farm is being upgraded in the timer service process. The task is 10% completed."

And Log file shows as


PSCONFIG] [SPManager] [INFO] [12/8/2012 5:11:10 AM]: psconfig: Spawing off the upgrade job
[PSCONFIG] [SPManager] [DEBUG] [12/8/2012 5:11:10 AM]: Creating exclusive upgrade reg key


I have tried stopping and restarting the SharePoint 2010 Product Configuration wizard. But no use.

Then finally i got solved it after spending 8 hours.

Here the steps to solve the error,

Step 1: I found with regedit that WSS_ADMIN_WPG and WSS_WPG's permission for "HKEY_LOCAL_MACHINE\Software\Microsoft\Shared Tools\Web Server Extensions\14.0\Secure" registry was somehow lost. I granted permission as described in post.

i. open run command and enter "regedit".
 and go to the path "HKEY_LOCAL_MACHINE\Software\Microsoft\Shared Tools\Web Server Extensions\14.0\Secure"
ii. and set WSS_ADMIN_WPG and WSS_WPG's permission for that registry.




Step 2: Clear PSConfig file's cache using the following batch file.
just download the following bat file from the following location and run it. Download here.

Step 3: Now run the following command
"PSConfig.exe -cmd upgrade -inplace b2b -force -cmd applicationcontent -install -cmd installfeatures"



Thats its.. enjoy....

and reference are here
http://social.technet.microsoft.com/Forums/en-CA/sharepointadminprevious/thread/8fa42032-e93e-464a-ad2c-8ac57d06fcf1

http://technet.microsoft.com/en-us/library/cc678863(v=office.14).aspx

http://social.technet.microsoft.com/Forums/en/sharepointadminprevious/thread/67c26d87-f725-4ce3-92c0-07b6aec526ff

http://www.toro-solutions.com/complete-installation-by-running-psconfig-utility/

Sunday, December 2, 2012

Programmatically how to create custom role and assign the role to a group

Create Custom Role with Custom permissions and assign role to group:

In this example i wanna create custom role with custom permission and assign that role to a group.

            using (SPSite site = new SPSite("http://UKREDDY:6969/"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPRoleDefinition network_role = new SPRoleDefinition();
                    network_role.BasePermissions = SPBasePermissions.AddListItems |
                        SPBasePermissions.BrowseDirectories |
                        SPBasePermissions.EditListItems |
                        SPBasePermissions.DeleteListItems;
                    network_role.Name = "CustomRole";
                    network_role.Description = "Provides permissions required for a member of a project.";

                    web.RoleDefinitions.Add(network_role);
                    // you can't just return definition because SharePoint gives you
                    //    "You cannot grant a user a permission level that is not
                    //    attached to a web" when you attempt to use it, so
                    //    you need to return it again
                    SPRoleDefinition newlyaddedef = web.RoleDefinitions["CustomRole"];
                    SPRoleAssignment assign = new SPRoleAssignment(web.SiteGroups["UdayGroup"]);
                    assign.RoleDefinitionBindings.Add(newlyaddedef);
                    web.RoleAssignments.Add(assign);
                    web.Update();
                }
            }





Delete custom role definition:


            using (SPSite site = new SPSite("http://UKREDDY:6969/"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    web.RoleDefinitions.Delete("CustomRole");
                }
            }

Get all groups,roles and users details in SharePoint

Get All Groups, Users and Roles in SharePoint:

In this example i wanna show how to get all groups , users and roles in SharePoint site.

            StringBuilder sb = new StringBuilder();
            using (SPSite site = new SPSite("http://ukreddy:6969/"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPGroupCollection groupCollection = web.SiteGroups;
                    foreach (SPGroup group in groupCollection)
                    {
                        SPUserCollection userCollection = group.Users;
                        sb.Append("Group Name :" + group.Name + "\n");
                        foreach (SPUser user in userCollection)
                        {
                            sb.Append("User Name: " + user.Name + " ; Email: " + user.Email + " ; Login: " + user.LoginName);
                            sb.Append("\n");
                        }
                        SPRoleCollection sprolecol = group.Roles;
                        foreach (SPRole role in sprolecol)
                        {
                            sb.Append("Role Name: " + role.Name + " ; Role Desc: " + role.Description + "\n");
                        }
                        sb.Append("\n");
                    }
                   MessageBox.Show(sb.ToString());
                }
            }

Programmatically how to assign user to SharePoint group

Assign a user to group:

In this example, i wanna show how to create group, assign role to the group and assign a user to the group.

            using (SPSite site = new SPSite("http://UKREDDY:6969/"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    web.AllowUnsafeUpdates = true;
                    web.SiteGroups.Add("UdayGroup", web.CurrentUser, web.CurrentUser, "This is Test Group for adding users to group.");
                    SPGroup group = web.SiteGroups["UdayGroup"];
                    SPRoleDefinition roleDefinition = web.RoleDefinitions.GetByType(SPRoleType.Contributor);
                    SPRoleAssignment roleAssigment = new SPRoleAssignment(group);
                    roleAssigment.RoleDefinitionBindings.Add(roleDefinition);
                    web.RoleAssignments.Add(roleAssigment);
                    web.Update();
                    SPUser spUser = web.EnsureUser("ukreddysykam\\urkeddy");
                    group.Users.Add(spUser.LoginName, spUser.Email, spUser.Name, spUser.Notes);
                    web.AllowUnsafeUpdates = false;
                }
            }





Programmatically how to assign,change and delete pred-defined roles to groups in SharePoint 2010

In my previous post shown how to create and delete groups. Now, i wanna show how to assign role to groups.

Create group and assign pre-defined role to SharePoint group:

Here am creating sample Test Group and assign contributor role to this group.

            using (SPSite site = new SPSite("http://UKREDDY:6969/"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    web.SiteGroups.Add("TestGroup", web.CurrentUser, web.CurrentUser, "This is Test Group created.");
                    //Getting newly created group
                    SPGroup group = web.SiteGroups["TestGroup"];
                    //Getting Pre-Defined Roles
                    SPRoleDefinition rDefination = web.RoleDefinitions.GetByType(SPRoleType.Contributor);
                    SPRoleAssignment rAssignment = new SPRoleAssignment(group);
                    //adding role definition to role assignment
                    rAssignment.RoleDefinitionBindings.Add(rDefination);
                    web.RoleAssignments.Add(rAssignment);
                    web.Update();
                }
            }



How add roles to existing groups:

In this example , showing how to assign roles to existing groups.

            using (SPSite site = new SPSite("http://UKREDDY:6969/"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPGroup group = web.SiteGroups["TestGroup"];
                    //Getting Pre-Defined Roles
                    SPRoleDefinition rDefination = web.RoleDefinitions.GetByType(SPRoleType.WebDesigner);
                    SPRoleAssignment rAssignment = new SPRoleAssignment(group);
                    //adding role definition to role assignment
                    rAssignment.RoleDefinitionBindings.Add(rDefination);
                    web.RoleAssignments.Add(rAssignment);
                    web.Update();
                }
            }

How  to delete a role from the group:

In this example, wanna show how to remove a role from the group.


            using (SPSite site = new SPSite("http://UKREDDY:6969/"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPGroup group = web.SiteGroups["TestGroup"];
                    SPRoleDefinition roleDef = web.RoleDefinitions.GetByType(SPRoleType.Contributor);
                    SPRoleAssignment roleAss = web.RoleAssignments.GetAssignmentByPrincipal((SPPrincipal)group);
                    roleAss.RoleDefinitionBindings.Remove(roleDef);
                    roleAss.Update();
                }
            }


How to delete all roles to a group:

In this example, i wanna show how to remove all roles from a group.

            using (SPSite site = new SPSite("http://UKREDDY:6969/"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPGroup group = web.SiteGroups["TestGroup"];
                    web.RoleAssignments.Remove(group);
                    web.Update();
                }
            }





Programmatically how to create and delete group in SharePoint 2010


Here i want to show how to create and delete groups using visual studio 2010.

Create Group:

            using (SPSite site = new SPSite("http://UKREDDY:6969/"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    web.SiteGroups.Add("TestGroup", web.CurrentUser, web.CurrentUser, "This is Test Group created by Uday.");
                    web.Update();
                }
            }


Delete Group:

Delete newly created group.

            using (SPSite site = new SPSite("http://UKREDDY:6969/"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    web.SiteGroups.Remove("TestGroup");
                    web.Update();
                }
            }