Thursday, November 4, 2010

Hiding “New Site” in Site Actions Menu

Today, I came across an interesting question in a forum and the question was.. “How to hide “New Site” option available in the Site Actions menu when the publishing feature is enabled.

Initially, I thought it would be easy with HideCustomAction element in a custom feature. However, it did not turn out to be that easy. After some investigation I figured out that that menu item is created by Publishing feature in code. HideCustomAction would have helped me if it was created declaratively. So, I took the same approach as Publishing feature to hide the menu. Here is the solution:

This was tough when I started doing it today. It is possible via feature using a CustomAction element in the elements.xml and some code. I tried a no-code solution but it was not possible.

 <CustomAction
        Id="HideCreateSiteInSiteActions"
        Location="Microsoft.SharePoint.StandardMenu"
        GroupId="SiteActions"
        Sequence="901"
        Title="Publishing SiteActions Menu Customization"
        ControlAssembly="Your Assembly full name"        ControlClass="your class full name">
  </CustomAction>

Following code would go in class:

public class YourClassName : WebControl
    {
        protected override void OnLoad(EventArgs e)
        {
            var siteActions = ToolBarMenuButton.GetMenuControl(this);
            siteActions.MenuControl.PreRender += (o, args) =>
            {
                var targetMenu = siteActions.GetMenuItem("MenuItem_CreateSite");
                if (targetMenu == null) return;
                siteActions.MenuControl.HiddenMenuItems.Add(targetMenu);
            };
        }       
    }

The scope of your feature would be "site". Also, don't forget to put SafeControl entry for your class in the web.config or it may not work.

Monday, November 1, 2010

I am active at StackOverflow.com and SharePointOverflow.com

Recently I came across a presentation from Scott Hanselman and he insisted that “Every Developer must have a blog.. period..”. After inspired by that presentation, I thought of giving it a try and I decided to spend a few hours every week for these two activities:

1. Help the community by answering the questions they have!

2. Blog interesting things that I come across

For the first activity, I decided to actively participate in SharePoint 2007/2010 related questions posted by people at StackOverflow.com and SharePointOverflow.com. I like these sites because they are simple and fast.. very simple reason indeed! And here I am, after one month of this activity, I gave about 50 answers and collected about 700 points. Wow, looking back, I did not anticipate that I would give that many answers and get many points! I must state that I enjoyed a lot while helping the community, I learnt a lot. Many of those answers that I have required me to research and even work with VS.NET to get the correct answer. So, I want to continue with this… and who knows after a year I may be recognized by Microsoft as an MVP… that would a quite an achievement.. pinch me, I am dreaming!

This blog and the posts that created last month is the proof of my second activity. Let’s see how many interesting things I come across and I am able to blog it or not!

Wrong values for Location and GroupID of Custom Actions specified in SharePoint SDK

While I was researching a problem reported by a user @ SharePointoverflow.com, I realized that if I wanted to add a link to Central Admin site’s “Site Collection” section of “Application Management” and use the Location and GroupID specified in SharePoint SDK, it would NOT work!

It wasn’t a pleasant surprise to me. The problem which lead me to investigate the issue is: http://www.sharepointoverflow.com/questions/6689/central-admin-custom-action-menu-not-appearing

If you are interested in correct values, please visit: http://bloggingabout.net/blogs/arjen/archive/2010/02/04/custom-action-definitions-in-sharepoint-2010.aspx

I finally found the problem and answered to the user. It turned out that I have to mark the feature element with AutoActivateInCentralAdmin="TRUE" so that when the feature which is scoped at “Web” would activate automatically in the central administration and display my custom action.

Thursday, October 21, 2010

Assigning Secondary Site Collection Administrators in bulk

 

I recently came across a situation where I needed to make a particular user the site collection administrator for all site collections within my web applications.

Thanks to the PowerShell for helping me automate this repetitive task. FYI, I used following command:

image

Wednesday, October 20, 2010

How to know if a document (lying in SharePoint Document Library) review is due…

I came across an interesting scenario when I was reading stackoverflow.com. Here is the scenario:

“In sharepoint 2010 I need to be able to set a review date on a document and be emailed when this review date is reached. Is this possible?”

I thought of researching on this and found a no-code solution for this. Please review my answer to above post. I will continue to monitor above post if I find a better answer.. But for now here is what I think:

 

To make it the most robust solution, I would suggest to customize the Alerts framework of SharePoint. SharePoint allows following customizations (as documented here http://msdn.microsoft.com/en-us/library/bb802949.aspx)

  • Adding or removing buttons from the alert e-mails.
  • Changing the cascading style sheet used to format e-mail alerts. This is particularly useful for sites that want to create a consistent appearance.
  • Changing the latency of "immediate" alerts by adjusting the default timer interval.
  • Override the templates used to create e-mail or SMS alerts, either by creating a new template or by setting the SPList.AlertTemplate property.
  • Creating custom filters by using Collaborative Application Markup Language (CAML) queries in the element in the alert templates.
  • Programmatically setting or changing the mobile messaging service provider (MSP) that forwards SMS alerts to mobile telephones.
  • Adding custom event handlers that respond when a user creates or modifies an alert. Also, custom handlers that respond to the alert sending event can be created.
  • Programming the alerts framework by using the SharePoint Foundation object model. For more information about how to customize alerts programmatically, see SPAlert.

If your list supports sending alerts based on a View, you are lucky, A NO CODE SOLUTION is already there for you. You can create a View with filter condition like "DueDate is equal to [Today]" (and possibly "AssignedTo is equal to [Me]) and then subscribe to any changes to that view.

If you end up with custom alert filter, following links may get you started: http://egrimmett.wordpress.com/2008/01/17/custom-alerts-part-2-filters/

http://blogs.msdn.com/b/sharepointdeveloperdocs/archive/2007/12/07/customizing-alert-notifications-and-alert-templates-in-windows-sharepoint-services-3-0.aspx

Monday, October 18, 2010

Creating a Web Application with all out of the box templates

As a SharePoint Developer, I am sure you would think about creating one site collections for all available web templates for learning purpose. I used to to do this as first thing after I was done with configuring my server farm. After doing it several times manually, I thought of automating it and I am sharing my experience here…

Welcome to the world of SharePoint 2010 and PowerShell, it is not too difficult to do this.

Here are the steps to do so….

First, we need to create Web Application that will host several Site Collections (as many as the out of the box web templates). I took an approach of creating a .csv file as an input to my web application script. For now, I will have just one row in my WebApps.csv but you can have as many as you want!

Here is the script which access the WebApps.csv file and creates web application:

Add-PsSnapin Microsoft.SharePoint.PowerShell
Import-Csv -Path "WebApps.csv" -Delimiter "," | ForEach-Object {New-SPWebApplication -Name $_.Name -Port $_.Port -ApplicationPool  $_.ApplicationPool -ApplicationPoolAccount (Get-SPManagedAccount $_.PoolAccount)}
Write-host "Operation was executed successfully."
Read-Host

For the purpose of this exercise, my WebApps.csv looks like:

image

Next, I created a list of site collections and then provisioned each site collection with out of the box site template I used same .csv approach above and used following PowerShell script to create the site collections:

Add-PsSnapin Microsoft.SharePoint.PowerShell
Import-Csv -Path "Templates.csv" -Delimiter "," | ForEach-Object {New-SPSite -Url $_.Url -OwnerAlias "Sp10\Administrator" -Language 1033 -Template $_.Name -Name $_.Title }
Write-host "Operation was executed successfully."
Read-Host

As you can see we needed an official name of the site template if you want to create a site collection programmatically. And I used another SharePoint cmdlet to get list of appropriate site templates as shown below

Get-SPWebTemplate | where { ( $_.'IsHidden' -eq [System.Boolean]$False ) -and ( $_.'IsSubWebOnly' -eq [System.Boolean]$False ) }

The result of above command would look like:

image

I used above result to create a .csv file that I need, my final Templates.csv file looks like:

Lcid,Title,Name,url
1033,Team Site,STS#0,http://#YourWebAppUrl#
1033,Blank Site,STS#1,http://#YourWebAppUrl#/Sites/Blank
1033,Document Workspace,STS#2,http://#YourWebAppUrl#/Sites/DocWS
1033,Basic Meeting Workspace,MPS#0,http://#YourWebAppUrl#/Sites/BasicMeetWS
1033,Blank Meeting Workspace,MPS#1,http://#YourWebAppUrl#/Sites/BlankMeetWS
1033,Decision Meeting Workspace,MPS#2,http://#YourWebAppUrl#/Sites/DecisionMeetWS
1033,Social Meeting Workspace,MPS#3,http://#YourWebAppUrl#/Sites/SocialMeetWS
1033,Multipage Meeting Workspace,MPS#4,http://#YourWebAppUrl#/Sites/MeetWS
1033,Blog,BLOG#0,http://#YourWebAppUrl#/Sites/Blog
1033,Group Work Site,SGS#0,http://#YourWebAppUrl#/Sites/GroupSite
1033,Document Center,BDR#0,http://#YourWebAppUrl#/Sites/DocCenter
1033,Records Center,OFFILE#1,http://#YourWebAppUrl#/Sites/Records
1033,Business Intelligence Center,BICenterSite#0,http://#YourWebAppUrl#/Sites/BI
1033,Enterprise Search Center,SRCHCEN#0,http://#YourWebAppUrl#/Sites/EntSearch
1033,Publishing Portal,BLANKINTERNETCONTAINER#0,http://#YourWebAppUrl#/Sites/PubPortal
1033,My Site Host,SPSMSITEHOST#0,http://#YourWebAppUrl#/Sites/mysite
1033,Enterprise Wiki,ENTERWIKI#0,http://#YourWebAppUrl#/Sites/EntWiki
1033,Basic Search Center,SRCHCENTERLITE#0,http://#YourWebAppUrl#/Sites/BasicSearch
1033,FAST Search Center,SRCHCENTERFAST#0,http://#YourWebAppUrl#/Sites/FASTSearch
1033,Visio Process Repository,visprus#0,http://#YourWebAppUrl#/Sites/Visio

You may want to change the data in .csv file as needed!

Hope you enjoyed reading this and save some time by automating this process!

Sunday, October 17, 2010

Crucial Real SSD C300 and SharePoint 2010

Today, I upgraded my SONY VAIO VPCF115FM laptop with Crucial RealSSD C300 256GB SSD Drive. This is my 3rd laptop upgrade in last 1 month; in fact, one of them was an upgrade to 7200 RPM HDD to Seagate Momentus XT Hybrid drive (from a regular 7200 RPM hard drive). The Hybrid drive significantly improved my laptop’s performance and I did not need SSD so badly! But I must call myself a gadget-freak, I could not wait!

Anyways, I spend high bucks for SSD because I wanted to get started with SharePoint 2010 development on VS.NET 2010 in 60 seconds! Before I switched to SSD, I noticed the performance of my older (it was still fastest performing platter based drive though, so don’t get surprised if you have same or comparable laptop and my number looks impressive!) drive.

My Environment:

Windows Server 2008 R2 with Domain Controller Role, SQL Server 2008 R2, SharePoint 2010, VS.NET 2008/2010

Performance of Seagate Momentus XT Hybrid 7200 RPM Drive

To see desktop wallpaper from Power On: 135 Seconds

To Browse google.com from power On: 150 seconds

Open Central Admin First time - 30-35 Seconds

VS.NET 2010 First Time- 12-15 Seconds

Microsoft Word – 5 seconds

 

Performance of Crucial RealSSD C300 SATA III 256GB Drive

To see desktop wallpaper from Power On: 70 Seconds

To Browse google.com from power On: 75 seconds

Open Central Admin First time - 30-35 Seconds

VS.NET 2010 First Time- 4-5 Seconds

Microsoft Word – 2-3 seconds

 

As you can see, SSD is performing much better than my already rocking Seagate Momentus XT Hybrid drive, perhaps the improvement may not be worth 550 bucks! Again, if I was comparing it with regular (non-hybrid) drive, the numbers would look very impressive, I vaguely remember it used to take about 220 seconds with regular 7200 RPM drive.

Time for final thoughts!

If you care of each and every seconds of improvement and ready to spend as much as you can, SSD is definitely a way to go. But if you are looking for a high capacity drive with maximum performance, go for Seagate Momentus XT 500GB drive, this performs really really good on Windows 7.