Saturday, January 28, 2012

Calendar Views: Hiding the time component in a single day event.


Time component being displayed in a single day event



In a calendar view, you may want to remove the time component displayed for single day events. Unlike MOSS 2007, the calendar view in SharePoint 2010 is displayed asynchronously after the page load. As a result, even if you try to fire a JavaScript /Jquery to remove these elements using the usual ‘_spBodyOnLoadFunctionNames.push('FunctionName');’ the code will not be able to find these elements simply because they would not be rendered by that time.

Mike Smith’s blog gives a wonderful solution to work around this problem. It worked for me !!




free counters

Monday, September 19, 2011

Migrating Existing Custom MOSS 2007 sites to SharePoint 2010

Various methods are documented on a high level by Microsoft here.
I preferred creating a site definition from the existing MOSS 2007 site and then restoring it in SharePoint 2010.

I have noted down the approach that I used in the process along with some references.



      1. Create a new site definition (based on Team Site) from scratch: Objective here is to start with a minimal site on which our custom site can be built.

      2. Using Solution Generator, Create list definitions for each list, include it in the project and then include it in your onet.xml

            3. Deploy the site definition once in SharePoint 2007 and test if the site gets restored.

      4. Convert & Deploy this site definition in SharePoint 2010.


       Note:
  •       The web-parts that might have been added through browsers in the web-part zones in SP 2007 will disappear. Those need to be added manually.
  •          Look up columns disappear from the restored list in SP 2010
              (Solution: The Field element is commented by Visual Studio. Need to uncomment it and replace the
ListId value with List URL (Relative))
  •          Your existing master page in 2007 would not be useful in 2010, as it would not support ribbon controls.
o   You may copy the contents of v4.master from SharePoint 2010 into your master page and build from there.
o    Another approach would be to add the content placeholders required for SharePoint 2010 into your master page.


       5. Convert & add the custom solutions into the site template solution and re-deploy the solution.

           6. Solutions developed in VS 2008 can be migrated to VS 2010 using the in-built converter in VS 2010.

             7. WSP Builder for VS 2010 can be installed to create WSP’s for such solutions

            8. <%@ Assembly Name="Microsoft.SharePoint.ApplicationPages, Version=12.0.0.0, 
                   Culture=neutral,PublicKeyToken=71e9bce111e9429c" %>

                   The above reference needed to be changed as given below on all application pages.
        <%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>

               9. An initialization feature receiver can be created and included in the ONET.XML file such that the feature  gets activated on site provisioning. The feature can be used for foll. purposes..
          A)     Groups to be created with the site can be added here.

                       10. Finally it may be converted to a web template in SharePoint 2010 to ensure it stays compatible with 
                            future versions of SharePoint.
                      (Refer an MSDN article here which indicates that ‘Site Definitions’ may no longer be supported in future versions of SharePoint)

          Advantages of this method:
                                                   i) Minimum efforts in recreating the list schemas in 2010 due to use of Solution Generator
                              ii) List forms and views will also get carried along using Solution Generator.
                              iii) All the custom code can reside in a single solution along with the Site Definition creating only one
                                  WSP.

          free counters

          Tuesday, July 19, 2011

          Clone SharePoint List Items


          A handy feature for your SharePoint lists would be ‘Cloning’ where the end users are allowed to Clone the existing list items. 

          This functionality can be achieved by providing a custom Ribbon button as shown below.
           
          List View before Cloning

          Clone Button in the ribbon




          Alert confirming the Cloning process

          Success message after cloning is done

          List View after Cloning

           
          Features:
          • A confirmation alert will be displayed to the users when they click on the ‘Clone’ button
          • The button would be enabled only if the user selects atleast one list item
          • A notification message is flashed at the top indicating whether the operation was successful or not.
          • Security: Only the users having the 'EditListItem' permission on the list will be able to Clone.


          Limitations:
          1. Attachments in the source item are not carried over.



          How the functionality was achieved

          1. A ‘CustomAction’ element was deployed and was attached to the ‘Generic Lists’ template
          2. Permissions are setup by configuring the ‘CustomAction’ element.
          3. The actual operation of cloning the list items was carried out using ECMA Script




          Contact me on rahulyvartak@gmail.com to get the full solution.



          free counters

          Tuesday, December 14, 2010

          Deploying SharePoint 2010 Sites using PowerShell

          This post will cover the following details..

          1. Deploying a complete site to another server (using Backup / Restore).

          2. Deploying a complete site to another server (using Site Template as a WSP) .

          3. Deploying increments done to another server (using Export / Import).

          4. Deploying WSP Solutions to another server.

          5. Upgrading the changes done to a WSP Solution into another server.


          A. Deploying a complete site onto another server:


          a. Consider a SharePoint site given below as the Source site where the development has taken place.

          Figure 1: Source SharePoint site to be deployed to another web-app / server

          b. As you can see, there are some minor changes that I have done to the default SharePoint site template. Also note the URL of the source site.

          c. To deploy this site onto some other site, we first need to backup this site.

          d. We can do so, either by using the STSADM commands or by using the PowerShell commands. As STSADM commands are scheduled to be deprecated, we will explore the PowerShell commands.

          e. In order to combine all the PowerShell commands that would be used while deployment, they can be written in a single .ps1 file. Follow the steps below to create one.

          f. Create a new file in Notepad and save it as a .ps1 file say ‘BackUpScript.ps1’.

          g. Right click on this file and click on ‘Edit’ as shown below:

          Figure 2: Edit the PS1 file


          h. Paste the following commands in it

          $file = "D:\Rahul\Backup.log"
          start-transcript $file
          trap { stop-transcript; break}
          Backup-SPSite -Identity "http://SERVER_NAME:PORT_NO/sites/Example/" -Path "D:/Rahul/SiteBackup.cmp" -Force -NoSiteLock
          stop-transcript

          Here is what the script does….

          $file is the variable where we define the path of the log file to be created.

          The output of the commands present between the start-transcript and the stop-transcript keywords will be shown on the screen as well as logged in the log file.

          The trap keyword is like an exception handling clause which continues to log the output in the log file even if an error is encountered.

          The Identity value should be assigned the URL of the source site.

          The Path value should be assigned the path where the log file would be stored

          The PowerShell command in normal case locks the site out so that no changes are allowed to the site while the backup takes place. The –NoSiteLock parameter does not lock the site.

          The file should look as shown below.

          Figure 3: BackupScript.ps1


          i. Open the ‘SharePoint 2010 Management Shell’ from the Windows menu.
          ii. Go to the path where the .ps1 file exists and execute the script using the command given below.
          ./BackUpScript.ps1  (Refer snapshot below)

          Figure 4: Running the BackupScript.ps1

           Note that if you are running the command from a normal command prompt, you need to first load the PowerShell snapin. The SharePoint Management Shell does it for us.

          iii. After the script gets executed, you will find two files created in the same folder.
          The log file and the backup file in ’.cmp’ format will be created as shown below.


          Figure 5: The log file and the backup file created
          iv. Now it’s time to deploy the site onto another server. 

          v. Create a DeployScript.ps1 file on the same lines and paste the foll. code in it
          $file = "D:\Rahul\Deployment.log"
          start-transcript $file
          trap { stop-transcript; break}
          Remove-SPSite -Identity "http:// SERVER_NAME:PORT_NO /sites/ExampleClone"
          Restore-SPSite -Identity "http:// SERVER_NAME:PORT_NO /sites/ExampleClone" -Path "D:/Rahul/ SiteBackup.cmp " -Force
          stop-transcript

          vi. Note that the SERVER_NAME:PORT_NO here should be the one of the destination site where we want the site to be deployed. The Remove-SPSite command is just an additional check just in case a previous version of the site already existed on the same URL

          vii. Execute the script from ‘SharePoint 2010 Management Shell’ in the same way as we did for the BackUpScript. While the script gets executed, it will ask for confirmation both while removing the site (i.e. in case it exists on the destination site) and while restoring the backup. Enter A on both instances as shown below.


          Figure 6: Confirmation asked before Removing / Restoring a site collection

          viii. The destination site should now be ready as shown below.
          For the sake of demonstration, I did it on the same server but on a different web application with a different port number. The same process can also be used to deploy it on a different server. 

          Figure 7: Site collection restored on the Destination web-app
          B. Deploying the complete site onto another server (using Site Template as a WSP)


          Another way to carry forward a complete site to another location is to create a Site template (which gets stored as a WSP in 2010) and then activate it on the destination server / web-app

          a. Browse to the source site collection.
          b. Click on ‘Site Actions -> Site Settings’ as shown below.

          Figure 8: Site Actions -> Site Settings

          c. Click on the ‘Save Site As Template’ link under the ‘Site Actions’ sub-menu as shown below.

          Figure 9: 'Save Site As Template' link
          d. Enter a template Name, a filename and check ‘Include Content’ if required as shown below. Click Ok.  

          Figure 10: 'Save as Template' Settings


          e. You should get a Successfully Created message along with a link to the Solution Gallery

          Figure 11: Success message on site template creation
           f. Go to the Solution Gallery and click on the newly created template. Save it to a location on your machine.

          g.  Now, Go to Create Site Collection page from the Central Admin, and while selecting the template… Select ‘Select template later..’ option under the ‘Custom’ tab as shown below

          Figure 12: Template Selection option while creating a site


          h. Click OK.
          i.   Browse to the newly created site and go to its Solution gallery
          j.  Click on ‘Upload Solutions’ link under the Solutions tab

          Figure 13: Upload Solution in the Solution Gallery
          k. Browse the template saved before and click Ok
          l.  Click on ‘Activate Solution’ link from the pop-up window that appears


          Figure 14: Activate the solution after it is uploaded
          m. The Solution gallery should now show the solution as activated
          n. Click on the Site Link at the top left and you should now be asked to select the template


          Figure 15: Site Link




           o. Select the Example Template that we uploaded as shown below. Click Ok

          Figure 16: Select the custom site template




          p.  You will be asked to setup access Groups.  Create new Groups or use existing groups and click OK

          Figure 17: Set Up Groups for the restored site




           q. The destination site would now be ready as shown below 

          Figure 18: Restored Site (after the uploaded site template is applied)

          r.   Given that you have a Site Template as a Sandboxed WSP ready, the process of creating a site from this custom site template can also be done using the following PowerShell script

          $file = "D:\Rahul\RestoreWSPSiteTemplate.log"

          start-transcript $file
          trap { stop-transcript; break}
          Remove-SPSite -Identity "http://DEST_SERVER_NAME:PORT_NO/sites/ExampleRestore"
          New-SPSite "http:// DEST_SERVER_NAME:PORT_NO/sites/ExampleRestore" -OwnerAlias domain\rahul.vartak 

          Add-SPUserSolution -LiteralPath "D:\Rahul\ExampleTemplate.wsp" -Site "http:// DEST_SERVER_NAME:PORT_NO/sites/ExampleRestore"

          Install-SPUserSolution –Identity ExampleTemplate.wsp -Site "http:// DEST_SERVER_NAME:PORT_NO/sites/ExampleRestore"

          $x = Get-SPSite "http:// DEST_SERVER_NAME:PORT_NO/sites/ExampleRestore"
          $y = $x.GetWebTemplates(1033) | Where{ $_.Title -eq "ExampleTemplate" }

          [system.reflection.assembly]::LoadWithPartialName("Microsoft.Sharepoint")
          $site= new-Object Microsoft.SharePoint.SPSite("http:// DEST_SERVER_NAME:PORT_NO/sites/ExampleRestore")
          $site.OpenWeb().ApplyWebTemplate($y)
          $site.Dispose()
          stop-transcript



          C. Deploying increments done onto another server (using Export / Import)  


          If your site is already deployed on the destination server, and you happen to create some lists / libraries or even a subsite; you can deploy the new lists, libraries or subsites with the help of Export / Import commands provided by PowerShell.

          The same can also be used if some data has been added to the lists existing before and needs to be deployed. Usually applies to master or configuration lists.

          Consider a SharePoint list ‘Knowledge Links’ in the source site that was created on the source site as shown below…


          Figure 19: 'Knowledge Links' list to be carried over to another server / web-app
          Now, if we have to push just this list onto another server which already has the same site deployed earlier without this list, we can do the following..

          ix. Use the Export-SPWeb command as shown below. 

          Export-SPWeb -Identity "http://SOURCE_SERVER_NAME:PORT_NO/sites/Example" -Path "D:/Rahul/ListBackup.cmd" -ItemUrl "Lists/Knowledge Links" -IncludeUserSecurity -Force  

          The ItemUrl parameter should be given the relative URL of the list that we are trying to export. 

          The IncludeUserSecurity parameter ensures that permissions that we have set on the list are also carried over.

          The Force parameter overwrites the backup file if another one already exists at the same folder location.

          x. Run the script and you should  find the exported list in specified folder in cmd format.

          xi. We can now use the following Import-SPWeb command to import the list onto our destination server.

          Import-SPWeb "http:// DEST_SERVER_NAME:PORT_NO /sites/ExampleClone " –Path "D:/Rahul/ListBackup.cmd" –IncludeUserSecurity

          Notice that we don’t have to specify what item we are importing here (i.e. ItemUrl) as that information is already contained in the cmp file. The Import command is thus generic and can be used for a subsite or a library as well.

          On running the import command, the list is generated as-is in the Destination web application as shown below. 


          Figure 20: 'Knowledge Links' list imported as-is onto another web-app / server
          The  Import-SPWeb command has several other switch parameters which may prove useful during deployment. Some of them are as follows.
          o   ActivateSolutions  : Adding this parameter will result in all user solutions being activated during import
          o   IncludeUserCustomAction : This parameter ensures that all the custom user actions are also included in the import

          More information can be found by running the following command in PowerShell.
          Get-Help Import-SPWeb -full

          The Export / Import Commands will also come to use in scenarios where the development requires the use of SharePoint Designer. In such cases, the customizations done through SPD can be carried over to different servers using Export / Import.

          Note 
          : While restoring sites, lists, and libraries using the import-SPWeb cmdlet, the previous data will get overwritten unless the -UpdateVersions parameter is passed in the operation, which requires versioning to be enabled on the destination list or library. Using -UpdateVersions enables you to restore the information contained in the backup without overwriting new items created in the destination list or library

          D: Deploying WSP Solutions to another server.

          Deploying WSP Solutions has been made easier by PowerShell Commands. Find below the list of PowerShell commands which will be used extensively while deployment.

          xii. Adding and Installing WSP Solutions 

          Add-SPSolution “D:\Rahul\SharePointSolution.wsp“
          Install-SPSolution –Identity SharePointSolution.wsp –WebApplication http://SERVER_NAME:PORT_NO  –GACDeployment

          If you wanna add the solution as sandboxed, you can use the Add-SPUserSolution and Install-SPUserSolution commands instead. The GACDeployment parameter will not be used in that case. 

          xiii. To retract and remove a solution, we can use the following commands:

          Uninstall-SPSolution –Identity SharePointSolution.wsp –WebApplication http:// SERVER_NAME:PORT_NO
          Remove-SPSolution–Identity SharePointSolution.wsp

          E: Upgrading changes done to the WSP Solutions.

          To upgrade a solution, we can specify which solution is to be updated and with which new solution file:
          Update-SPSolution –Identity SharePointSolution.wsp –LiteralPath “D:\Rahul\SharePointSolution.wsp” –GacDeployment




          free counters