Recent Blogs

AvatarByRashid Aziz

Get SharePoint Webpart Usage Report

 

During an extranet migration to office 365 we need to find out a custom content editor webpart usage.  That web part was used in many location that I would be waste of time to find all the references. I decided to write a query again extranet site content database to find out webpart usage.

The first thing we need is the “Webpart type ID”. Download this tool from http://easywebparttypeidgen.codeplex.com/releases/view/48886  and follow the instruction http://easywebparttypeidgen.codeplex.com/  to retrieve webpart type ID.

Now open SQL management studio and run the below query against SharePoint site content database.

Note:  Make sure that you have replaced the ‘Webpart type ID here’ with the right 32 digit webpart type id in the below query before you run it.

SELECT DISTINCT D.SiteID, D.WebId, W.FullURL as WebURL, D.Id As DocumentId,

D.DirName, D.LeafName, tp_ID As WebPartSK

FROM       dbo.Docs D WITH (nolock) 

INNER JOIN dbo.Webs W WITH (nolock) ON D.WebID = W.Id

INNER JOIN dbo.WebParts WP WITH (nolock) ON D.Id = WP.tp_PageUrlID

WHERE WP.tp_ListId Is Null AND WP.tp_Type Is Null AND WP.tp_Flags Is Null

AND WP.tp_BaseViewID Is Null AND WP.tp_DisplayName Is Null 

AND WP.tp_Version Is Null

AND WP.tp_WebPartTypeId='Webpart type ID here'

Run the query and you will see the result table with all webpart references.

If you have multiple content databases then you can run this query against each of them to find all webpart references.

 

AvatarByRashid Aziz

Avoid password prompt while open a document in SharePoint

To make SharePoint site a trusted site in order to avoid multiple logon prompts while opening or downloading a document, these following changes are required on client pc.

1. Open Internet Explorer

2. Log on to the site http://SharepointSiteCollectionURL/  or simply copy and paste this URL if you cannot access the site

3. On the Internet Explorer menu bar, select the “Tools” menu, then select “Internet Options”

4. Select the “Security” and then click “Trusted Sites” zone

5. Click the “Sites” button

  • Add the portal address in the “Add this website to the zone” box. Click “Add”
  • Don’t check “Require server verification (https) for all sites in this zone”  option
  • If the site web address is not in the input field, then copy and paste it from the browser address at the top of your browser window.
  • Click on “close”

6. Under the trusted site zone Click on the “Custom Level” button

7. Scroll down to the middle and enable the “Display mixed content”

8. Scroll down to the bottom

  • Under “User Authentication/Logon”, select “Automatic logon with Current Username and Password” and click “OK”

9. Click “OK” twice to close all dialog boxes

10. Close all instances of internet explorer

11. The next time you open Internet explorer and log on to site make sure the “Remember my password” option is selected on “Authentication dialog”

12. Now go to a document library and try to download or open a document in MS office, it should not prompt you for credential again.

Enjoy ! J

AvatarByRashid Aziz

Custom rich text editor styles for Content editor web part

 

I received a request from business to restrict site editor not to use OOTB fonts and styles while they edit the contents of “Content editor web part” in SharePoint 2010. This is nice to have if you want consistent look and feel across the site without much end end-user training. 

They asked me to create custom styles; apart from those styles the editor should not be able to apply any font, colours or styles on CEWP contents.

I have done these changes on “Page Layout”. If an editor creates any page using that page layout, he/she will only see custom styles while editing the “content editor web part” contents.

Below are the detailed steps to achieve this kind of functionality

1. Create custom CSS file (In my case I will call it “CustomRTStyles.css”) with custom styles , also hides OOTB fonts and mark-up styles options and upload it to “/Style Library/en-us/Core Styles/ CustomRTStyles.css”

(Change the below CustomRTStyles.css style sheet according to your requirement)

/* Custom rich text editor Styles list */

.custom-rteStyle-Heading1

{-ms-name:"Heading 1";

 color:#FF0000;

 font-size:30px;

 font-family:"Gill Sans MT";

 font-weight:bold;}

.custom-rteStyle-Heading2

{-ms-name:"Heading 2";

 color:#000000;

 font-size:24px;

 font-family:"Gill Sans MT";

 font-weight:bold;}

.custom-rteStyle-Heading3

{-ms-name:"Heading 3";

 color:#000000;

 font-size:20px;

 font-family:"Gill Sans MT";

 font-weight:bold;}

.custom-rteStyle-Heading4

{-ms-name:"Heading 4";

 color:#000000;

 font-size:18px;

 font-family:"Gill Sans MT";

 font-weight:bold;}

.custom-rteStyle-Paragraph

{-ms-name:"Paragraph";

 color:#969393;

 font-size:14px;

 font-family:"Arial, Helvetica, sans-serif" }

.custom-rteStyle-IntroParagraph

{-ms-name:"Intro Paragraph";

 color:#000000;

 font-size:12px;

 font-family:"Arial, Helvetica, sans-serif"}

/* To hide fonts tab */

#Ribbon\.EditingTools\.CPEditTab\.Font

{  display:none;} 

/* To hide Markup styles tab */

#Ribbon\.EditingTools\.CPEditTab\.Markup

{display:none;}

2. Open the default master page in SharePoint 2010 designer and add the reference to newly created CSS style-sheet. 

//
<link rel="stylesheet" type="text/css" href=" /Style%20Library/en-us/Core%20Styles/CustomRTStyles.css" />

Now save and publish the master page.

3. Open the page layout in SharePoint designer on which you what to apply custom editing styles.

4. Locate the RichHtmlField and add the following properties

PrefixStyleSheet=”custom-rte” AllowFonts=”false”

The < RichHtmlField > control with look like the following

//
<PublishingWebControls:RichHtmlField FieldName="PublishingPageContent"  HasInitialFocus="True" PrefixStyleSheet="custom-rte" AllowFonts="false" MinimumEditHeight="400px" runat="server"/>

Reference custom css inside page layout just before the <PublishingWebControls:EditModePanel> control 

//
<SharePointWebControls:CssRegistration name="<% $SPUrl:~sitecollection/Style Library/~language/Core Styles/CustomRTStyles.css %>" runat="server"/>

5. Now add the jquery to force the “Content editor web part” to use custom styles while editing any contents.  Locate the <PublishingWebControls:EditModePanel runat=”server”> and add the scripting inside it, the end result will look like following

<PublishingWebControls:EditModePanel runat="server">

<!-- Styles for edit mode only-->

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>

<script type="text/javascript">

ExecuteOrDelayUntilScriptLoaded(function() {

 // window.setTimeout(function() {

 $("div[RteRedirect]").each(function() {

var id = $(this).attr("RteRedirect"),

editSettings = $("#" + id);

if(editSettings.length > 0 && editSettings[0].PrefixStyleSheet != 'custom-rte') {

editSettings[0]['PrefixStyleSheet'] = 'custom-rte';

editSettings[0]['StyleSheet'] = '\u002fStyle Library\u002fen-US \u002fCore Styles\u002fCustomRTStyles.css';

 RTE.Canvas.fixRegion(id, false);

 }

 });

// }, 2000);

}, "sp.ribbon.js");

</script> </PublishingWebControls:EditModePanel>

6. Save and publish the page layout.

7. Now create new page in SharePoint 2010 page library by using updated page layout and add “Content editor web part”. The rich text editing tool will look different. I have attached the before and after images to give you guys feelings how the end results would look like.

 

Before changes

 

After changes

AvatarByRashid Aziz

SharePoint 2010 library “New Document” option is greyed out

 We have upgraded a SharePoint intranet site form SharePoint 2007 to 2010. While I was fixing the minor issues in new site I came across this issue. I could not create any document in document library because the “New Document” option was greyed out in ribbon as shown below.

There was not any issue with permissions as I was the site collection administrator. There are couple of different options to try to fix this issue.

  1. Enable “Client Integration” in web application settings.
  2. Disable “User Access Control” UAC .Check the following article http://www.petri.co.il/disable-uac-in-windows-7.htm
  3. Go to Library > Library settings > Advanced settings  > and  Allow management of content types to TRUE
AvatarByRashid Aziz

Create reusable content in InfoPath 2010

 I had a requirement in past where I need to create an InfoPath form which will be reusable for other custom solutions.

I have decided to create a re-useable template in InfoPath 2010. I think it’s worth showing the steps.

I have created employee info form which was going to be used again several times. So, I have created the form by drag and drop contents to the pane and the end result are look like this.

Once the form is ready follow these steps

Steps:

Now go to file and click “Save as” link. Give new template a name and save it on local disk.

Now from the controls section of the ribbon, click “Expand all controls” and then click “Add or Remove Custom Controls”.

A new window will appear, now click on “Add” and follow the wizard by selecting template part and browse to the location where you saved the template earlier. Now your custom control is successfully added.

Create now form using custom control

Close the InfoPath 2010 tool and re open, create new solution and select blank form template. From the control menu select employee info control (control created in the first section) and the form will appear instantly. Now you can do the changes if want and save it.

It is very important that you create re-useable contents to save development time and efforts. J

AvatarByRashid Aziz

SharePoint 2010 time zones setting programmatically

The SharePoint 2010 server is always set to a specific time zone. Users from all over the world can change the time zone by using “My regional settings”. I wanted to achieve this programmatically as a batch operation.

To do this, I have used the following code.

SPRegionalsettings spRegnal= new SPRegionalSettings(web, true);
spRegnal.TimeZone.ID = 2 ;     // Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London
User.RegionalSettings= spRegnal ;

The SPRegionalSettings takes two parameters, the SPWeb and a Boolean. Set the time zone ID and finally get the SPUser object and assign the regional settings to that user.

 

AvatarByRashid Aziz

Change authentication mode in SharePoint 2010

 In the following article I will explain how to change SharePoint 2010 authentication mode. In the following example I will change authentication provider of SharePoint 2010 web application from windows authentication to claim base authentication.

To do this you need to user SharePoint 2010 management shell

Go to start menu > All programmers > SharePoint 2010 products > SharePoint 2010 management shell

Type and execute the following command

$WebAppName = “http://eblogin.com”

$account = “SPdomain\ebloginAdmin”

$wa = get-SPWebApplication $WebAppName

Set-SPwebApplication $wa –AuthenticationProvider (New-SPAuthenticationProvider) –Zone Default

A confirmation message will appear, type “Y” and press enter

Now check the authentication provider from central admin. It should show “claims based authentication”.

AvatarByRashid Aziz

Testing custom solution options for SharePoint Online (office 365)

Deploying and testing solution to SharePoint online is different from SharePoint on premises environment. For SharePoint online we can only create sandbox solutions which are site collection scoped.

There are two options for SharePoint online testing environment

1. Create new site collection

Our goal here is to provide separate environment for testing solutions. SharePoint sandboxed solutions are site collection scoped, so we can create new site collection for testing custom solution before deploying it to production site collection.

This option will not work if your code required making changes on tenant level.  E.g. if you are making use of BCS, this might be not a good option.

2. New Office 365 account (tenant)

If you want to make sure that there should be a separate environment for testing in cloud, then consider this option. You can buy a test environment license for few users, or a 30 days trial version can be used for testing purpose.

AvatarByRashid Aziz

SharePoint 2010 rich text editing tool styles

I came across a scenario where my client wants SharePoint extranet site contents look and feel consistent. The site have many sub sites and which lot of publishing pages, editors can create pages, add content editor web part and add contents.

The request routed to me about deleting some custom styles from content editing tool and adding some new ones.

Solution

Open the current “Master” page in SharePoint 2010 designer.

Click “Style” tab from designer menu and select “Manage styles”

Right click any CSS style from” Manager Style” list  and select “Go to code”

The core CSS file has all styling references ; the style starts with name “.ms-rteStyle”.

Create new styles as

.ms-rteStyle-stylename

{-ms-name:"Eblogin Style"; color:#00adee;}

Save the Core.css file

Note: YOU CAN ALSO DELETE THE EXISTING STYLES BEFORE SAVING THE CSS FILE

Open the SharePoint site and go to a page which has content editor web part.

Edit any content inside the content editor web part and try to select the style from editing tool. You will see new style as shown below

AvatarByRashid Aziz

Potentially excessive number of SPRequest objects, SharePoint error

I got this error in ULS log file while using one SharePoint application which was developed by third party. I have checked the code and it was disposing the SP objects correctly.

The site was running really slow, and it takes about 40 seconds to load the home page.

Site structure:

Our application has 5 sites under a site collection and about 500 sub sites underneath those 5 sites.

Reason of error:

The “show subsites” option in navigation setting was checked, so when the page loads it also load 5 sites in navigation menu and all 500 sub sites links as a dropdown link menu. The navigation menu is shipped with SharePoint product, the way it is designed that it use SP Request object to build each navigation link and doesn’t dispose those object automatically (Reason: if the page do refresh, it does not need to re-create all object again)

Resolution:

Go to site collection home page

Click site action> site settings

Click “Navigation” link under “Look and Feel” section

Uncheck “Show sub sites” under “global navigation” and “current navigation” as shown below

If you need that navigation link for all sub sites should be available for user, think about other ways to getting this functionality (e.g. custom navigation), or reconsider your application structure.

Results:

After doing the above changes, I did not see any log saying “Potentially excessive number of SPRequest objects“. Also site performance increased dramatically as the home page loads in 4 seconds. J

Hope this will help.