Monthly Archive May 2012

AvatarByRashid Aziz

Programmatically show processing screen in SharePoint 2010

Some time when writing a custom solution in SharePoint which takes some time to process, it is nice to show end user some message screen saying something like “Please wait we are dealing with your request”.

In SharePoint 2010 this functionality is available out of the box, we can call SPLongOperation class in code and display the below screen with custom message and also can redirect to a different page after completion.

// Initialise SPLongOperation object and specify message you want end users to see.
SPLongOperation lp = new SPLongOperation(this.Page);
lp.LeadingHTML = "<div><h2>Processing Request</h2></div>";
lp.TrailingHTML = "<div><h3>Please wait, your request is being processed</h3></div>";
// long running code start 
// long running code end
lp.End(Customers.DefaultViewUrl, Microsoft.SharePoint.Utilities.SPRedirectFlags.Default, this.Context, "");

I hope this will help.

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  and follow the instruction  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 */


{-ms-name:"Heading 1";



 font-family:"Gill Sans MT";



{-ms-name:"Heading 2";



 font-family:"Gill Sans MT";



{-ms-name:"Heading 3";



 font-family:"Gill Sans MT";



{-ms-name:"Heading 4";



 font-family:"Gill Sans MT";






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


{-ms-name:"Intro Paragraph";



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

/* To hide fonts tab */


{  display:none;} 

/* To hide Markup styles tab */



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="" 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
  3. Go to Library > Library settings > Advanced settings  > and  Allow management of content types to TRUE