Saturday, 4 January 2014

Add a custom button SharePoint 2010 ribbon that executes server-side code


In this blog, we learn about the Microsoft SharePoint 2010 ribbon by adding or removing a custom button that executes server-side code.

To add button into ribbon follow below steps:

1.     Click Microsoft Visual Studio 2010.



2.     On the File menu, point to New, and then click Project.



3.     In the New Project dialog window, in the Installed Templates section, click Visual C#, click SharePoint, and then click 2010.

4.     Click Empty SharePoint Project from the project items.

5.     In the Name box, type RibbonDemo and then click OK.



6.     In the SharePoint Customization Wizard, type the local Web site that you want to use for this exercise (such as http://localhost/SampleWebSite).

7.     For the trust level, select Deploy as a farm solution and then click Finish.




8.     In Solution Explorer, right-click the RibbonDemo node, point to Add, and then click New Item.



9.     In the Add New Item dialog screen, in the Installed Templates section, click Visual C#, click SharePoint, click 2010, and then click the Empty Element item type.



10.  Leave the Name as EmptyElement1 and then click OK.

11.  In Solution Explorer, right-click the EmptyElement1 node and then click View Code.

12.  Delete the contents of the Elements.xml file.

13.  Add the following code to the Elements.xml file.



<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
  Id="DemoHelloWorldButton"
  RegistrationType="List"
  RegistrationId="101"
  Location="CommandUI.Ribbon">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition
         Location="Ribbon.Documents.New.Controls._children">
          <Button
           Id="Ribbon.Documents.New.Controls.DemoHelloWorldButton"
           Alt="Hello World Ribbon Button"
           Sequence="10"
           Image32by32="/_layouts/images/PPEOPLE.GIF"
           Command="Demo_HelloWorld"
           LabelText="Hello World Demo"
           TemplateAlias="o2"/>
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler
         Command="Demo_HelloWorld"
         CommandAction="javascript:alert('Hello World!');" />
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>
</Elements>


14.   In Solution Explorer, right-click the RibbonDemo node and then click Deploy.

15.   Open the Web site specified previously.

16.   Click the Documents tab in the SharePoint 2010 ribbon.




17.   You should see the new Hello World Demo button added to the ribbon.
Click Hello World Demo. The Hello World JavaScript dialog box appears as shown Figure


To remove button into ribbon follow below steps:
1.       In Solution Explorer, right-click the EmptyElement1 node and then click View Code.

2.       Comment the existing code by typing <!-- in front of the opening <CustomAction> element. Next, type --> after the closing </CustomAction> element.

3.       After the commented code, insert the following code.


 
 
<HideCustomAction Id="Ribbon.Documents.New.Controls.DemoHelloWorldButton" Location="Ribbon.Documents.New.Controls._children">
</HideCustomAction>

4.       Deploy and test the updated solution by following steps 1 through 4 in Task 3, Deploy and Test the Solution.


 Product applies to:

SharePoint Server 2010
SharePoint Foundation 2010

Saturday, 21 September 2013

How to disable Edit My Profile button from SharePoint My Site template

Problem Description:

In SharePoint My Site template "Edit My Profile" option is present.
If user click on that link,then they can change their details,which get reflected into Active Directory.
So our on of the client doesn't want to give permission to user to change their profile data.

When i see URL, thoughts.aspx page is present in _layouts folder.



Resolution:

Step 1: Open SharePoint layouts folder.

            (How to access layout folder)

Step 2: Open 
thoughts.aspx file in notepad.

Step 3 : As shown in below image hide div tag.


Step 4: Open  thoughts.aspx in IE.


Product applies to:

·     SharePoint Server 2010

·     SharePoint Foundation 2010


How to access layout folder in SharePoint

Problem Description:

Where is the _layouts directory on the server?

Resolution:

Sharepoint 2010 layouts folder:

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\

If you're using SP 2007 the folder is

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\


Product applies to:

·     SharePoint Server 2010

·     SharePoint Foundation 2010

Could not load the Web.config configuration file. Check the file for any malformed XML elements, and try again. The following error occurred: The given key was not present in the dictionary.

Problem Description:

I tried to debug SharePoint project in Visual Studio 2010. I found error where deploying project/solution is fine, but debugging doesn’t work. I saw an error alert with the text:
“Could not load the Web.config configuration file. Check the file for any malformed XML elements, and try again. The following error occurred: The given key was not present in the dictionary.”



The Web.config doesn’t have any error. One thing to check into is the configuration of alternate access mappings in Central Administration.
For debugging to work, the Site URL property of our SharePoint project must match the URL of the Default zone for your web application.

Resolution:

Step 1: Go to Central Administration

Step 2: System Setting

Step 3: Configure alternate access mappings

Step 4: Edit public URLs



Step 4: Set Default URL same as Visual Studio
(In this case make it as http://SiteName:20103)





Product applies to:

·     SharePoint Server 2010
·     SharePoint Foundation 2010


Saturday, 31 August 2013

SharePoint Designer - Cannot perform this operation. The file is no longer check out or has been deleted


Problem Description:
The css file showed itself as being checked out when it was actually checked in.

Error Message:

SharePoint Designer - Cannot perform this operation. The file is no longer check out or has been deleted 



Resolution:

The problem is to delete your temporary internet files and to clear your website cache of all files. (Search WebsiteCache into My Computer) After this, everything will work again.

Product applies to:

·                     SharePoint Server 2010
·                     SharePoint Foundation 2010



Feel free to revert in-case of any query...

Thursday, 4 July 2013

SharePoint master page css styles not showing for users other than site administrator.


Today I face one tricky problem in SharePoint 2010.
When I login through site administrator then CSS which I apply on master page work fine,
But when I login through other users CSS effects are not visible on master page.


Error Message:

SharePoint master page css styles not showing for users other than site administrator.


Problem Description:

        This usually happens when the CSS file or master page is not published or approved yet or it may be Check-In.

  •  After system administrator login, Menu Bar from Master page look like this.





  •  After normal user login, Menu Bar from Master page look like this.
  •  Here CSS is not apply.



Resolution:

To Approve Master page Follow below steps:

1.             Open the SharePoint Designer using System Administrator Account.



2.             From Site Object select Master Page

3.             Select your default Master page. (E.g. V4.master)

4.             On “Site Page Gallery”, see “View” section and that click on “Approve/reject. Items” view.



5.             You will see the view is “Group By” by “Approval Status. (E.g. Draft, Approved) 
        Basically Approval Status is divided into 4 different status like Draft, Pending, Approved,Reject


6.             Then Search your default Master page in Draft section select it and send for Approval.




7.             Refresh your page, your default Master page will shown in Pending status section, Select and Approve it.




8.             Finally default master page get approved by System Administrator,
          means it get publish for all user on site.




Product Applies To:         SharePoint Server 2010
Feel free to revert in-case of any query... 

Monday, 1 July 2013

Hide SharePoint list column from form using designer.

Problem Description: 

Hide SharePoint list column from form using designer. 
Resolution:
Step 1:- Select column from design view. Eg. PickupDateTime
Step 2:- Search attribute class of “<td>” tag as “ms-formlabel” and “ms-formbody” for Label and control respectively.


Step 3:- And Change that class name as “ms-hidden” for both Label as well as Control.


Product Applies To:
 
·         SharePoint Server 2010 
·         SharePoint Foundation 2010 
·         SharePoint Server 2013
 
Feel free to revert in-case of any query...