Thursday, 25 December 2014

SharePoint 2013 Upgrade Step by Step From SharePoint 2010

In this article we can see how to upgrade SharePoint 2007 to SharePoint 2010. When you upgrade from SharePoint 2010 Products to SharePoint 2013, you must use a database attach upgrade, which means that you upgrade only the content for your environment and not the configuration settings. After you have configured a new SharePoint 2013 environment, you can copy the content and service application databases from the SharePoint 2010 Products environment to the SharePoint 2013 environment. You use a backup and restore process to copy the database, and you can also choose to set the databases to read-only in the SharePoint 2010 Products environment so that users can continue to access their information, but not change it.

Back up the SharePoint 2010 Products databases by using SQL Server tools
  1. Verify that the user account that is performing this procedure is a member of the db_owner fixed database role for the databases.
     
  2. In Management Studio, in Object Explorer, connect to an instance of the Database Engine, expand the server, and then expand Databases. 
     
  3. Right-click the database that you want to back up, point to Tasks, and then click Back Up. 
     
  4. The Back up Database dialog box appears.
     
  5. In the Source area, in the Database box, verify the database name.
     
  6. In the Backup type box, select Full.
     
  7. Under Backup component, select Database.
     
  8. In the Backup set area, in the Name box, either accept the backup set name that is suggested or type a different name for the backup set.
     
  9. In the Destination area, specify the type of backup destination by selecting Disk or Tape, and then specify a destination. To create a different destination, click Add.
     
  10. Click OK to start the backup process.
Restore a backup copy of the database
  1. Verify that the user account that is performing this procedure is a member of the db_owner fixed database role for the databases.
  2. After you connect to the appropriate instance of the SQL Server 2008 Database Engine, in Object Explorer, expand the server name.
  3. Right-click Databases and then click Restore Database. 

    Restore-a-backup-copy-of-the-database.jpg
     
  4. The Restore Database dialog box appears.

    Restore-Database-dialog-box.jpg
     
  5. In the Restore Database dialog box, on the General page, type the name of the database to be restored in the To database list.
  6. In the To a point in time text box, keep the default (Most recent possible).
  7. To specify the source and location of the backup sets to restore, click From device, and then use the ellipsis (...) to select the backup file.
  8. In the Specify Backup dialog box, in the Backup media box, be sure that File is selected.

    Specify-Backup-dialog-box.jpg
     
  9. In the Backup location area, click Add.
  10. In the Locate Backup File dialog box, select the file that you want to restore, click OK, and then, in the Specify Backup dialog box, click OK.
  11. In the Restore Database dialog box, under Select the backup sets to restore grid, select the Restore check box next to the most recent full backup.
  12. In the Restore Database dialog box, on the Options page, under Restore options, select the Overwrite the existing database check box.

    Overwrite-the-existing-database-check-box.jpg
     
  13. Click OK to start the restore process.

    start-the-restore-process.jpg
To attach a content database to a web application by using Windows PowerShell

Verify that you have the following memberships:
  • Securityadmin fixed server role on the SQL Server instance.
  • db_owner fixed database role on all databases that are to be updated.
  • Administrators group on the server on which you are running the Windows PowerShell cmdlets.
  1. Start the SharePoint 2013 Management Shell.
  2. For Windows Server 2008 R2:
  3. On the Start menu, click All Programs, click Microsoft SharePoint 2013 Products, and then click SharePoint 2013 Management Shell.
  4. For Windows Server 2012:
  5. On the Start Screen, click SharePoint 2013 Management Shell.
  6. If SharePoint 2013 Management Shell is not on the Start Screen:
  7. Right-click Computer, click all apps, and then click SharePoint 2013 Management Shell.
  8. At the Windows PowerShell command prompt, type the following command and then press ENTER:

    Windows-PowerShell-command-prompt.jpg
Mount-SPContentDatabase -Name DatabaseName -DatabaseServer ServerName -WebApplication URL

Where:
  • Database Name is the name of the database that you want to upgrade.
  • Server Name is server on which the database is stored.
  • URL is the URL for the web application that will host the sites.
To view the Upgrade Status page
 
  1. Verify that the user account that is performing this procedure is a member of the db_owner fixed database role for the databases.
     
  2. In Central Administration, click Upgrade and Migration, and then click Check upgrade status.
To view the upgrade log file

The upgrade error log file and the upgrade log file are located at %COMMONPROGRAMFILES%\Microsoft Shared\web server extensions\15\LOGS. The upgrade log file contains more detailed information than the upgrade error log. Be sure to check the summary at the bottom of the log files for information about the overall status and a count of the warnings and errors in the file.
  • The logs are text files named in the following format:
  • Upgrade-YYYYMMDD-HHMMSS-SSS-error.log
  • Upgrade-YYYYMMDD-HHMMSS-SSS.log
Where

YYYYMMDD is the date

HHMMSS-SSS is the time (hours in 24-hour clock format, minutes, seconds, and milliseconds)

An example for an upgrade error log is Upgrade-20120105-132126-374-error.log, and an example for an upgrade log is Upgrade-20120105-132126-374.log.

To attach a content database to a web application by using Windows PowerShell

Verify that you have the following memberships:
  • securityadmin fixed server role on the SQL Server instance.
  • db_owner fixed database role on all databases that are to be updated.
  • Administrators group on the server on which you are running the Windows PowerShell cmdlets.
  • An administrator can use the Add-SPShellAdmin cmdlet to grant permissions to use SharePoint 2013 cmdlets.
Start the SharePoint 2013 Management Shell.

For Windows Server 2012:
  1. On the Start Screen, click SharePoint 2013 Management Shell.
  2. If SharePoint 2013 Management Shell is not on the Start Screen:
  3. Right-click Computer, clicks All apps, and then click SharePoint 2013 Management Shell.
     
  4. For more information about how to interact with Windows Server 2012, see Common Management Tasks and Navigation in Windows Server 2012.
     
  5. At the Windows PowerShell command prompt, type the following command and then press ENTER:

    Mount-SPContentDatabase -Name DatabaseName -DatabaseServer ServerName -WebApplication URL

    Windows-PowerShell-command-prompt1.jpg
Where:
 
  • DatabaseName is the name of the database that you want to upgrade.
  • ServerName is server on which the database is stored.
  • URL is the URL for the web application that will host the sites.
Upgrade a site collection

To upgrade a site collection

Verify that the user account that performs this procedure is a site collection administrator.
 
  1. On the Site Settings page for the site collection, in the Site Collection Administration section, click Site collection upgrade.
     
  2. On the Site Collection Upgrade page, click Upgrade this Site Collection.

    Upgrade-a-site-collection.jpg
     
  3. This option starts the process of upgrading your site collection. A box opens to verify that you want to start the process.

    Upgrade-a-site-collection1.jpg
     
  4. Click I'm ready to start the actual upgrade.

    Upgrade-a-site-collection2.jpg

     
  5. The upgrade starts, and the Upgrade status page for the site collection is displayed. This page automatically updates while the upgrade is in progress and displays information about the process, such as the following: 

    Upgrade-a-site-collection3.jpg
     
  6. The Upgrade will show you the progress as shown below:

    Upgrade-a-site-collection4.jpg
     
  7. Once done with the upgrade, a page will display the information as shown below:

    Upgrade-a-site-collection5.jpg
     
  8. Once successfully migrated you will get the 2007 site upgraded with SharePoint 2010 as shown below:

    Upgrade-a-site-collection6.jpg



 

How to Identify the Version and Service Packs installed on a SharePoint 2013 Server

In many cases, we may not be bothered about the Version, Service Packs installed on our Server when we do the development. It is obvious that, when we get the requirement, immediately we will start analysis the requirement.
But recently there was a situation that one of our client wants to move on to the new Service Pack which released on this April. In that case, we may also have to analyze the impact of the new Service Pack. Before knowing that, I just wanted to know, what are the things installed on our Dev environment first. Then on top of it, what needs to be installed and what would be the impact after installation.
To answer all these questions, First we need to know what is the version installed on our Farm.
Use the following command to get the Version of the product installed using PowerShell script.
(Get-SPFarm).Products
The output of the above command will be something like,
image
By seeing the GUID, we will be able to identify the Product. These GUIDs will not change. On all the environments, and all the machines, the GUIDs will remain same.
Here are all of the product GUIDs:
GUIDProduct
35466B1A-B17B-4DFB-A703-F74E2A1F5F5EProject Server 2013
BC7BAF08-4D97-462C-8411-341052402E71Project Server 2013 Preview
C5D855EE-F32B-4A1C-97A8-F0A28CE02F9CSharePoint Server 2013
CBF97833-C73A-4BAF-9ED3-D47B3CFF51BESharePoint Server 2013 Preview
B7D84C2B-0754-49E4-B7BE-7EE321DCE0A9SharePoint Server 2013 Enterprise
298A586A-E3C1-42F0-AFE0-4BCFDC2E7CD0SharePoint Server 2013 Enterprise Preview
D6B57A0D-AE69-4A3E-B031-1F993EE52EDCMicrosoft Office Web Apps Server 2013
9FF54EBC-8C12-47D7-854F-3865D4BE8118SharePoint Foundation 2013
And to know about the Service Packs, there is no need of any PowerShell Commands. That we can directly go to the Central Administration and find.
1. Go to Central Administration.
2.image
3. Click on “Upgrade and Migration” on the Quick Links.
4.image
5. Click on “Check Product and Patch Installation Status”
6.image
7. This will tell us the current Patches Installation. By seeing the Version column we can identify. On the screen shot above shared, there is no SP installed. You can download the latest Service Pack from Here.
8. To Identify the Version through C#, please refer the linkhttp://msdn.microsoft.com/en-us/library/jj659075.aspx

Programmatically Manage List Items Rating with Social Rating Manager in SharePoint 2013

As the title describes, I am going to share about the Rating functionality (GetRating and SetRating) of a SharePoint 2013 List Item by using SocialRatingManager Class programmatically.
Before starting to that, there are certain basic settings, we need to do before proceeding to the manage rating programmatically.

Enabling the Rating Settings
· This needs to be done on the List level. Before doing any rating, we need to enable the rating settings on the List Settings.

clip_image002
· Click on the List Settings.
clip_image004
· Click on the Rating Settings and Enable the Rating Functionality

clip_image006
Permissions on the User Profile Service Application
· Need to Give permissions on the UserProfile Service Application.
· On the CentralAdministration, Select the UserProfile Service Application.

clip_image008
· Click on the Administrators
· Add the User and give him full permission.

clip_image010

· Come back to Permissions Section.

clip_image012

· Give the user Full Control.

clip_image014

Timer Jobs Responsible for the List Item to reflect the Rating.
There are 2 timer jobs, which are responsible to reflect the Rating value on the List Item through the UI. i.e., When we do a Rating for a particular item through code, it will not get reflected immediately on the SharePoint UI. It will get reflect only after the timer gets executed. The timer jobs are as follows.
1. Social Rating Synchronization Job
2. Social Data Manager Timer Job.
These 2 jobs can be viewed on by going to Central Administration -> Monitoring -> Review Job definitions
The frequency of the Job, by default would be 1 hour. Hence, whenever, we made any Rating, this will be reflected after an hour only. To avoid the delay, we can modify the frequency of the timer as one minute. But even then, I couldn’t find any alternate way that, the rating will get reflected immediately. Please do let me know, if someone finds a way for that.
With this fundamental settings, coming to our core topic J .
Basically, I faced a requirement like, we need to rate an item from the Provider Hosted Application. As all of us are well aware that, from PHA, only the Client Side Object Model can be used to talk with SharePoint. At that time, I was searching for a Client Side Object for SocialRatingManager. UnFortunately, there is no CSOM object for SocialRatingManager. Hence Planned to develop a WCF Service and Host it in the SharePoint Farm. By making use of the REST call, access this WCF Service and call the GetRating Method from the Provider Hosted Application. The below image can express requirement and the solution clearly.
clip_image016
To achieve this transanction, from PHA, only CSOM is allowed. But there is no CSOM Object for SocialRatingManager. Hence the solution would be Introducing a WCF Service.
clip_image017
With the introduction, let us go to the SetRating method. The below lines of code are self explanatory.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
 /// <summary>
 /// This will return the User Name in the correct format
 /// </summary>
 /// <param name="spUser"></param>
 /// <returns></returns>
 private static string GetUpn(string spUser)
 {
     string[] userName = spUser.Split('\\');
     System.DirectoryServices.ActiveDirectory.Domain domain =
         System.DirectoryServices.ActiveDirectory.Domain.GetCurrentDomain();
     return userName[1] + "@" + domain.Name;
 }
  
 /// <summary>
 /// This will take the required parameter from the PHA and start the rating functionality
 /// </summary>
 /// <param name="ColumnName"></param>
 /// <param name="Value"></param>
 /// <param name="ListName"></param>
 /// <param name="RatingValue"></param>
 /// <param name="RatingTitle"></param>
 /// <returns></returns>
 public string SetRatings(string ColumnName, string Value, string ListName, string RatingValue, string RatingTitle)
 {
     try
     {
         //Getting the values of the Sitecollection url and user in the format of domain\UserName from the Query string, as it cannot be passed as a parameter to the WebService Method
         string SiteURL = Convert.ToString(System.Web.HttpContext.Current.Request.QueryString["URL"]);
         string ImpersonatedUser = Convert.ToString(System.Web.HttpContext.Current.Request.QueryString["USER"]);
  
         ULSLog.LogDebug("Entering into SetRatings Method");
         bool bSetRating = false;
         SPSecurity.RunWithElevatedPrivileges(delegate()
         {
             using (SPSite site = new SPSite(SiteURL))
             {
                 SPWeb web = site.AllWebs["MYSite in which the List resides"];
                 SPList list = web.Lists[ListName];
                                              
  
  
                 SPQuery qry = new SPQuery();
  
  
                 string selectCmd = "<Where><Eq><FieldRef Name='" + ColumnName + "'/><Value Type='Text'>" + Value + "</Value></Eq></Where>";
  
                 qry.Query = selectCmd;
                 qry.RowLimit = 1;
                 SPListItemCollection lstitmcol = list.GetItems(qry);
  
                 if (lstitmcol.Count > 0)
                 {
  
                     SPListItem item = lstitmcol[0];
  
                     web.AllowUnsafeUpdates = true;
                     //This is the Actual SetRating Method.
                     SetRatingForListItem(item, Convert.ToInt32(RatingValue), RatingTitle, ImpersonatedUser);
                     web.AllowUnsafeUpdates = false;
                     bSetRating = true;
                 }
                 else
                     bSetRating = false;
             }
         });
         return bSetRating == true? "Success" : "Failure";
     }
     catch (Exception ex)
     {
         ULSLog.LogError(ex);
         return ex.Message;
     }
  
 }
  
 /// <summary>
 /// This is the one which is doing the actual rating functionality.
 /// </summary>
 /// <param name="listItem"></param>
 /// <param name="ratingValue"></param>
 /// <param name="ratingTitle"></param>
 /// <param name="user"></param>
 private void SetRatingForListItem(SPListItem listItem, int ratingValue, String ratingTitle, string user)
 {
  
  
     //We are Impersonating the User context with the current logged user.  This is because, the rating should happen on behalf of the person, who is rating.  When the same person rates the same item again, then the rating count will not increased.  It will be Updated for the same entry.
     IPrincipal impersonationPrincipal = new WindowsPrincipal(new WindowsIdentity(GetUpn(user)));
  
     HttpRequest request =
     new HttpRequest(string.Empty, listItem.Web.Url, string.Empty);
  
     HttpResponse response =
         new HttpResponse(
         new System.IO.StreamWriter(new System.IO.MemoryStream()));
  
     HttpContext impersonatedContext =
     new HttpContext(request, response);
  
     impersonatedContext.User = impersonationPrincipal;
     impersonatedContext.Items["HttpHandlerSPWeb"] = listItem.Web;
  
     HttpContext.Current = impersonatedContext;
  
     SPServiceContext serviceContext = SPServiceContext.GetContext(impersonatedContext);
     Uri uri = new Uri(String.Format("{0}/{1}", listItem.Web.Url, listItem.Url));
  
     SocialRatingManager ratingManager = new SocialRatingManager(serviceContext);
     ratingManager.SetRating(uri, ratingValue, ratingTitle);
     //After setting the SetRating method, we need to call the PropogateRating method.  This will avoid the delay in the reflecting time.  (i.e., waiting for the timer to get executed).  But unfortunately, I could not find any impact with this method.
     ULSLog.LogDebug("SetRating Completed");
 }

Now we were able to SetRating successfully. Now we need to fetch the rated information from the ListItem. To achieve that, the following piece of self explanatory code will be helpful.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
 public class Rating
 {
 public float floatAverage{get;set;}
  
 public int ratingCount { get; set; }
  
  
          
 }
  
 /// <summary>
 /// This method is being called from the PHA.
 /// </summary>
 /// <param name="ColumnName"></param>
 /// <param name="Value"></param>
 /// <param name="ListName"></param>
 /// <returns></returns>
 public Rating GetRatings(string ColumnName, string Value, string ListName)
 {
     try
     {
         Rating socialRating = new Rating();
         string SiteURL = Convert.ToString(System.Web.HttpContext.Current.Request.QueryString["URL"]);
         string ImpersonatedUser = Convert.ToString(System.Web.HttpContext.Current.Request.QueryString["USER"]);
  
         ULSLog.LogDebug("Entering into GetRatings Method");
  
         SPSecurity.RunWithElevatedPrivileges(delegate()
         {
             using (SPSite site = new SPSite(SiteURL))
             {
  
                 SPWeb web = site.AllWebs["My Site "];
                 SPList list = web.Lists[ListName];
  
   
  
                 SPQuery qry = new SPQuery();
  
  
                 string selectCmd = "<Where><Eq><FieldRef Name='" + ColumnName + "'/><Value Type='Text'>" + Value + "</Value></Eq></Where>";
  
                 qry.Query = selectCmd;
                 qry.RowLimit = 1;
                 SPListItemCollection lstitmcol = list.GetItems(qry);
  
                 if (lstitmcol.Count > 0)
                 {
                     SPListItem item = lstitmcol[0];
                     socialRating = GetRatingsForListItem(item, ImpersonatedUser);
                 }
                 else
                 {
                     ULSLog.LogDebug("No Items Found");
                     socialRating = null;
                 }
  
             }
         });
  
         ULSLog.LogDebug("Leaving GetRating Method");
         return socialRating;
     }
     catch (Exception ex)
     {
         ULSLog.LogError(ex);
         return null;
     }
 }
  
 /// <summary>
 /// This is the actual method which will be used to Fetch the rating information from the RatingManager
 /// </summary>
 /// <param name="listItem"></param>
 /// <param name="ImpersonatedUser"></param>
 private Rating GetRatingsForListItem(SPListItem listItem, string ImpersonatedUser)
 {
     ULSLog.LogDebug("Entering GetRatingsForListItem Method");
  
     Rating rating = new Rating();
     string ItemURL = String.Format("{0}/{1}", listItem.Web.Url, listItem.Url);
  
  
     IPrincipal impersonationPrincipal = new WindowsPrincipal(new WindowsIdentity(GetUpn(ImpersonatedUser)));
  
     HttpRequest request =
     new HttpRequest(string.Empty, listItem.Web.Url, string.Empty);
  
     HttpResponse response =
         new HttpResponse(
         new System.IO.StreamWriter(new System.IO.MemoryStream()));
  
     HttpContext impersonatedContext =
     new HttpContext(request, response);
  
     impersonatedContext.User = impersonationPrincipal;
     impersonatedContext.Items["HttpHandlerSPWeb"] = listItem.Web;
  
     HttpContext.Current = impersonatedContext;
  
     Uri uri = new Uri(String.Format("{0}/{1}", listItem.Web.Url, listItem.Url));
  
     SPServiceContext serviceContext = SPServiceContext.GetContext(impersonatedContext);
  
     SocialRatingManager ratingManager = new SocialRatingManager(serviceContext);
  
     SocialRatingAverage average = ratingManager.GetAverage(uri);
  
     rating.floatAverage = average.Average;
              
     rating.ratingCount = ratingManager.GetCount(uri);
  
     if (rating.ratingCount == 0)
         rating.floatAverage = 0;
  
     ULSLog.LogDebug("Leaving GetRatingsForListItem Method");
  
     return rating;
 }
With this we are done with the GetRating and SetRating.
The issue which I faced during the development was,
Rating.floatAverage = average.Average; -> This line will be throwing null. But after giving the permission on the Permissions tab in Central Administration, I was able to get the RatingAverage.