Search This Blog

Saturday, November 23, 2013

Developing SharePoint 2010 User Interface Ribbon

Exercise 1 – Adding a custom button to the Ribbon

In this exercise, we will extend the ribbon by adding our own custom button that executes server-side code. We can use this approach to add or replace buttons, groups, tabs, or even the whole ribbon. We will use a Visual Studio 2010 solution and deploy it to the local SharePoint server.
The button will pop up a JavaScript dialog box displaying the “Hello World” message.

Task 1 – View the site

We will view the site before we add a button to the Ribbon so that we know what the Ribbon displays like OOTB.

1.    Open Internet Explorer and browse to http://intranet.contoso.com
2.    Select the Shared Documents library from the Documents menu in the left-hand navigation section (quick launch).
 

Figure 4 - Shared Documents

3.    In the Library Tools tab of the Ribbon that appears, select the Documents tab.


Figure 5 - Documents Tab
1.     This Ribbon is the location where the new button we will be creating in this exercise will appear.

Task 2 – Create a SharePoint 2010 Empty Project

In this task, a solution and project will be created. It will contain the rest of the development work in this exercise.

1.    Open Visual Studio 2010 by going to the Start Menu | All Programs | Microsoft Visual Studio 2010 | Microsoft Visual Studio 2010.
2.    From the menu, select File | New | Project.
3.    In the New Project dialog box, expand the Installed Templates left-hand menu to Visual C# | SharePoint | 2010 and choose the Empty SharePoint Project project type in the project type list in the middle section of the screen.
4.    Enter RibbonDemo in the Name textbox.
5.    Enter C:\SPHOLS\SPCHOL308\CS\Ex1 in the Location textbox.
6.    Click OK.
7.    A SharePoint Customization Wizard dialog box will appear.
8.    In the What local site do you want to use for debugging? textbox, type http://intranet.contoso.com
9.    For the What is the trust level for this SharePoint solution? radio buttons, choose Deploy as a farm solution.

Figure 6 - SharePoint Customization Wizard
10.  Press Finish to complete the customization wizard.
11.  Visual Studio 2010 will generate the necessary project files and folders.
12.  Your Solution Explorer should now look like the following image.


Figure 7 - RibbonDemo Solution Explorer

Task 3 – Add the button code to the project

13.  Right-click the RibbonDemo project node in Solution Explorer and choose Add | New Item…
14.   In the Add New Item dialog box, expand the Installed Templates left-hand menu to Visual C# | SharePoint | 2010 and choose the Empty Element item type in the middle section of the screen.
15.  Leave the Name as EmptyElement1.
Figure 8 - Add New Item - Ribbon Demo
16.  Click Add to add the element to your project.

Figure 9 - Elements Xml

17.  Delete the contents of the Elements.xml file.
18.  Add the following code to the Elements.xml file. You can find a copy of this file in the Supporting Files\SPCHOL308\Resources\CS folder.
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction
   Id="DemoHelloWorldButton"
   RegistrationId="101"
   RegistrationType="List"
   Location="CommandUI.Ribbon"
   Sequence="5"
   Title="Hello World">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition
         Location="Ribbon.Documents.Manage.Controls._children">
          <Button
           Id="Ribbon.Documents.New.Controls.DemoHelloWorldButton"
           Alt="Hello World Ribbon Button"
           Sequence="10"
           Command="Demo_HelloWorld"
           Image32by32="/_layouts/images/ribbondemo/demobutton.png"
           LabelText="Hello World Demo"
           TemplateAlias="o1"/>
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler
         Command="Demo_HelloWorld"
         CommandAction="javascript:alert('Hello World!');"
         />
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>
</Elements>
Code Snippet: My Xml Snippets | spchol308_ex1_ xml

Figure 10 - Elements Xml Updated
19.  Take note of the Image reference, this is the image that will display in the Ribbon, we will add this image next.
20.  Take note also of the CommandScript, this is the JavaScript that will execute upon pressing of the button we are adding to the ribbon.
21.  Add a folder to the solution that maps to the Images folder in the SharePoint layouts directory where we can put our button image.  Right-click the RibbonDemo project node, and choose Add | SharePoint “Images” Mapped Folder.

Figure 11 - Add Mapped Folder
22.   The Images folder appears with a sub folder for our button.

Figure 12 - Images Folder
23.   Add the DemoButton.png file by right-clicking the new RibbonDemo folder and choosing Add | Existing Item…
24.  When the dialog box appears navigate to C:\Content Packs\Packs\SharePoint 2010 Developer Labs 1.0\SUPPORTING FILES\SPCHOL308\Resources\ and select the DemoButton.png file.

Figure 13 - DemoButton Image

Task 4 – Deploy the solution

25.  In the Solution Explorer, right-click on RibbonDemo and select Deploy.

Figure 14 - Deploy Solution
26.  The solution will be deployed to the SharePoint site.
27.  Open a web browser and browse to the local SharePoint site:

28.  If prompted for authentication, enter the following details:
Username: administrator
Password: pass@word1
29.  In the left navigation, click on the Shared Documents link to open the Shared Documents library.

Figure 15 - Shared Documents link
30.  Click on the Documents tab in the SharePoint Ribbon.

Figure 16 - Documents tab
31.  You should see the new button Hello World added to the SharePoint Ribbon.

Figure 17 - Hello World Buton
32.  Click the Hello World Demo button in the Ribbon to see the Hello World JavaScript dialog box appear.

Figure 18 - Hello World Demo

In the past few minutes you have demonstrated how to add new custom button and extend the SharePoint button.

SharePoint 2010–Hiding "Sign in as Different User"

SharePoint 2010–Hiding "Sign in as

 Different User"


The "Sign in as Different User" is a bad idea for a lot of reasons, but the two biggest are:
  • Security on the computer where "User B" wants to access SharePoint. While at this computer they could perform any number of actions as "User A".
  • Mixed experiences when using software other than a browser. As an example, "User B" can "Sign in as Different User" on the "User A" computer. Everything done from the browser, such as adding list items, is logged as "User B", but many actions performed from Word, Outlook and other tools will be logged as "User A"
"Sign in as Different User" is available from the Welcome menu and from the Access Denied page:
clip_image002[6] clip_image002[8]

How a Site Owner can hide "Sign in as

 Different User"

You can hide the "Sign in as Different User" option by adding a small block of JavaScript code to your site's master page just before the </body> tag.
<script type="text/javascript"> 
var doc = document.getElementsByTagName('ie:menuitem');  
for (var i = 0; i < doc.length; i++)  
{
    itm = doc[i];
    if (itm.id.match('LoginAsDifferentUser') != null)
      { itm.hidden=true; }
 } 
</script> 
Note: You can still "Sign in as Different User" by navigating directly to the Access Denied page:
  http://yourserver/sites/yoursite/_layouts/AccessDenied.aspx

How a developer or server administrator

 can hide "Sign in as Different User"

As there are two ways a user can get to the "Sign in as Different User" option you will need to make two different changes, one to the Welcome menu and one to the Access Denied page.
Warning:
  • Changes to ControlTemplates and Layouts folder impact all users on all sites in the farm!
  • Changes to the pages in the ControlTemplates and Layouts folder need to be documented as farm rebuilds or service pack updates could overwrite your changes.
  • You should make a backup copy of any files you edit.
  • All changes must be made identically on all web front end servers.
Updating the Welcome menu
The Welcome menu is implemented as an ASPX user control (.ascx) and is stored in the …\14\TEMPLATE\CONTROLTEMPLATES folder. Editing this file impact all users on all sites in the farm. You may want to use the "Site Owner" solution listed earlier in this article. Another option is to create a copy of the Welcome.ascx file and modify selected master pages to point to the custom version of the file.
  1. Open the Welcome.ascx file (or your custom copy) using Notepad or Visual Studio from
        …\14\TEMPLATE\CONTROLTEMPLATES 
  2. Find the MenuItemTemplate with the ID of ID_LoginAsDifferentUser
  3. Then do one of the following
    • Delete the MenuItemTemplate control
    • Add these two options to the MenuItemTemplate control to limit the display of the menu item to only Site Owners
         PermissionsString="ManageWeb"
         PermissionMode="Any"
Updating the Access Denied page (AccessDenied.aspx)
  1. Open the AccessDenied.aspx page using Notepad or Visual Studio:
       …\14\TEMPLATE\AccessDenied.aspx
  2. Find the following code:
      <asp:HyperLink id="HLinkLoginAsAnother"
      Text="<%  $SPHtmlEncodedResources:wss,accessDenied_logInAsAnotherOne%>"
      CssClass="ms-descriptiontext" runat="server"/>
  3. Then do one of the following:
    • Delete the code
    • Wrap the code in a comment block
    • Wrap the code in a SPSecurityTrimmedControl with a permission level such as ManageWeb (see this article) so Site Owner can still see the option.
<Sharepoint:SPSecurityTrimmedControl runat="server" PermissionsString="ManageWeb">
  <asp:HyperLink id="HLinkLoginAsAnother"
  Text="<%$SPHtmlEncodedResources:wss,accessDenied_logInAsAnotherOne%>"
  CssClass="ms-descriptiontext" runat="server"/>
</SharePoint:SPSecurityTrimmedControl>

New features in SharePoint 2010

New features in SharePoint 2010

1. Access Services:
2. Business Connectivity Services:
3. Central Administration:
4. Digital Asset Management:
5. Enterprise Search(Fast Search);
6. Excel Services:
7. Health Monitoring:
8. Managed Metadata:
9. Performance Point Services:
10. Record Management:
11. Sandboxed Solutions:
12. Social Computing:
13. Visio Services:
14. User Profile Services:
15. Windows Power Shell:
16. Client Object Model:

Sunday, October 13, 2013

Enable Sign in as Different User Option in SharePoint 2013

In this post we are going to see how to enable the sign in as different user option in SharePoint 2013. Till SharePoint 2010 this option was by default available but in SharePoint 2013 for some reason this has been not visible by default.

so if you want this option to be available then you need to add following line of code to the welcome.ascx which is located at :\Program Files\Common Files\microsoft shared\Web ServerExtensions\15\TEMPLATE\CONTROLTEMPLATES.

Add this to the welcome.ascx file. But a note to consider, please take the backup of the welcome.ascx file before you attempt this step.

<SharePoint:MenuItemTemplate runat="server" ID="ID_LoginAsDifferentUser" Text="<%$Resources:wss,personalactions_loginasdifferentuser%>" Description="<%$Resources:wss,personalactions_loginasdifferentuserdescription%>" MenuGroupId="100" Sequence="100" UseShortId="true" />

And then you should have the sign in as different user option available.

Tuesday, October 1, 2013

On SharePoint, Hide the “Sign – in As A Different User” option through JQuery Or Other Options

A simple script you can add to your master page or content editor etc. to hide the “Sign in As a Different User” option that is available in the Personal Actions Menu.
<script src="/jQuery/jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/JavaScript">
jQuery(document).ready(function($) {
var objects = document.getElementsByTagName("ie:menuitem");
for (var i = 0; i < objects.length; i++) {
itm = objects[i];
if (('#' + itm.id).indexOf("LoginAsDifferentUser") != -1) {
$('#' + itm.id).remove();
}
}
})
</script>
********************************************
Go to C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\CONTROLTEMPLATES\
You there have a file call welcome.ascx and have action to  "LoginAsDifferentUser"
<SharePoint:MenuItemTemplate runat="server" id="ID_LoginAsDifferentUser"
                Text="<%$Resources:wss,personalactions_loginasdifferentuser%>"
                Description="<%$Resources:wss,personalactions_loginasdifferentuserdescription%>"
                MenuGroupId="100"
                Sequence="100"

                UseShortId="true"/>

Monday, September 30, 2013

What is the difference between Item.Update() and Item.System.update()?

Generally when we try to add/edit a SPListItem using SharePoint Object Model? Yes I know it! Almost everybody have common answer to this (which is similar to what is provided below).
       SPListItem item = SPList.Item.Add();
       Item[“Col1”] = “Value for Col1”;
       Item[“Col2”] = “Value for Col2”;
       Item.update();
The last line in the code above "item.Update()" does the final task of updating all the assigned value for that specific item within the SPList.
But is this the only way to update an item? No, we can also update the same item using item.SystemUpdate();

Then what is the difference between the two?

With item.update(), we update the changes that are made to the list item. Is that all what it does? No, internally it also updates the “ModifiedBy” and “ModifiedOn” fields as per the current logged in user and current server time. Optionally it also updates the version of the item if the versioning option is turned on for that specific list.
So, at any point if we wish not to update these extra things I.e. the “ModifiedOn” , “ModifiedBy” and the “Item Version”, then the solution for it is to use item.SystemUpdate() instead of item.Update().This will help you in updating only those fields which are specified within your code blocks.

 Conclusion: item. Update () will update the changes that are made to the list item as well as “ModifiedBy”, “ModifiedOn” and “ItemVersion” If Version is enabled.

item.SystemUpdate() will updates the changes that are made to the list item only, it will not update the “ModifiedBy”, “ModifiedOn” and “ItemVersion”.


Thursday, September 26, 2013

Site Collection Backup and Restore in SharePoint 2010

Site Collection Backup and Restore in SharePoint 2010

We work tirelessly to create, edit, and enhance sites and site collections; sometimes making hundreds of hours of changes. It would be a shame to lose all of this work simply because no one backed-up the site collection and disaster struck.
The backup and restore processes are both simple, and easy to use. The most important part of the process is knowing that a site collection backup can be done either from Central Administration or from Windows Management Shell; however a site collection restore can only be done via Windows Management Shell.

Site Collection Backup:

No matter which method you use, you must first create a folder to store the backup.
If you choose to use Windows Management Shell the next step is to run a backup script.

The script follows the syntax: Backup-SPSite <SiteCollectionURL> –Path <BackupFile>
The great thing about backups is that you can name your file, so if you need to number your backups or base the name on the site collection, it is a simple task.

If you choose to use Central Administration, the process is done through the User Interface:
Central Administration > Backup and Restore > Perform a site collection backup
Which leads you to this page:
From here you can choose the site collection you wish to backup, and then specify the location where the backup file will be stored- in this case it is the same location used via Windows Management Shell.

If you are not sure of the URL of the site collection you wish to backup then Central Administration is a safer route because you can browse through all site collections to find the one you wish to backup. However, if you have many site collections and already know the URL then Windows Management Shell is easier to use.

Site Collection Restore:

Remember, a site collection restore can only be done via Windows Management Shell:
The restore script follows similar syntax to the backup script: Restore-SPSite <DestinationSiteCollectionURL> -Path <BackupFile> [-Force]
In this case the Force command is in brackets because it is optional- if you already have a site collection at the specified URL you must force the restore, but if the URL is not being used then you don’t need the Force command.
It is a good idea to backup the site collections once a week. The operation is simple, but can take up space if you start backing up daily so be cautious as to how often you backup, and be sure to delete old backups.

The Top 50 SharePoint Sites:

As SharePoint continues to grow in popularity within organizations large and small, the number of SharePoint related online resources has skyrocketed. There are a lot of excellent ones, so we thought we’d put together a list of our 50 favorites.
Please note that this is by no means an exhaustive list of all the great SharePoint sites out there, nor is it in any particular order. If you find there’s a blog or site that hasn’t been included in this list that you think is awesome, then leave us a comment and let us know!

  • SharePoint Joel
  • NothingbutSharePoint
  • Wonder Laura
  • SharePoint in Education
  • CMS Wire
  • Portals and KM
  • Andre Connell
  • 21 Apps
  • Dave Coleman’s SharePoint and Technology Blog
  • Nauplius
  • Broculos
  • ShareMuch
  • Jeremy Thake’s Musings
  • Randy Drisgill
  • Stefan Gossner’s Technet Blog
  • Paul’s Project Server Blog
  • TN Chris Bortlik’s Blog
  • The Guide of Mobile MOSSLover
  • Fear and Loathing
  • Chris O’Brien’s The Nuts and Bolts of SharePoint
  • SharePoint Adam
  • Adis Jugo: The Southern Side – SharePoint Bits and Bytes
  • SharePoint Javascripts
  • Furuknap’s SharePoint Corner
  • Marc D Anderson’s Blog
  • SharePoint Analyst HQ
  • Harbar.net
  • Views from Veronique
  • Point Beyond
  • A Soldier of Fortune
  • Tobias Zimmergren
  • The SharePoint Viking
  • Todd Klindt’s SharePoint Admin Blog
  • Microsoft…what else?
  • Rez’s SharePoint Blog Spot
  • Dot Net Mafia
  • Meet Dux
  • Eblogin
  • Matthias Einig: SharePoint, TFS and Powershell
  • Seb 2.0
  • Elio Struyf
  • John Chapman’s SharePoint Blog
  • Metalogix
  • David Lozzi’s Blog
  • Salaudeen Rajack’s SharePoint Diary
  • KWizCom SharePoint Blog
  • Tom Resing’s SharePoint Blog
  • Chris McNulty’s KnowPoint
  • Cameron Dwyer: OnePlaceMail, SharePoint, Outlook & Life’s Other Little Wonders
  • SharePoint Dev Notes
  • SharePoint Wendy