- podcast
- research
- search
- security
- technology
- video
- AIM
- Alfresco
- Collaboration
- ECM
- ESX
- Hyper-V
- IE8
- Internet Explorer
- Iomega
- Linux
- MIX08
- Microsoft
- NAS
- Nokia
- REV
- S60
- SaaS
- Sharepoint
- Silverlight
- Sony Ericsson
- VMware
- Windows Live
- YouTube
- advertising
- backup
- beta test
- blogs
- convergence
- display
- enterprise
- humans
- instant messaging
- multimedia
- networking
- open source
- phishing
Redirect a Custom Page in SharePoint 2010
An event receiver in SharePoint allows great flexibility to meet various user requirements, and with each version of SharePoint there are improvements to enhance their usability.One of these added abilities is to redirect a user to a custom page while cancelling the event from an event receiver. Lets consider this scenario: an HR department wants to place a new policy which requires all the users to only upload documents into a document library from 9 a.m. to 5 p.m. Moreover, as this is a new policy, there should be a page that displays the details of the new policy, whenever a user upload is cancelled. The following diagram shows the flow.
Now, an Item Adding event receiver will take care of the first part of the requirement, but for the second part there is no OTB support to achieve this in SharePoint 2007. However, SharePoint 2010 provides an excellent way to do this, with little effort. The following steps shows the detail of how to achieve this.
First, create a new Visual Studio 2010 Beta 2 Solution and expand SharePoint 2010 from Installed Template; select project of type Event Receiver. Give desired names to the solution and project. My previous article covers the event receiver project creation and some required configuration in detail, if you need more help, please refer to it.
The SharePoint Customization Wizard will appear. In type of Event Receiver select List Item Events. Select Document Library from event source drop down. Also select the checkbox for An item is being added from the list of available events. See the figure below.
After the project is created, create a page that will be displayed when a document upload is declined. For this, add a layouts folder to the project. You can do it by right clicking on the project and select SharePoint Layouts Mapped Folder; see the figure below.
This will create a layouts folder, actually a subfolder with the same name as your project. This layout folder basically corresponds to SharePoint 2010 Layouts folder inside the 14 hive.
Right click this subfolder inside the Layouts folder, and select Add, New Item. This will open a new dialog, select Application Page, and use HRDocumentUplaodMessage.aspx as a name.
Click Add. This will add this application page to the layouts subfolder. Add the simple texts as shown below into the mentioned tags. The basic idea is to keep it simple, but this page can be made as much detailed and complex as required.
In order to add the logic to cancel the document upload, and show the custom page, add the following code fragment into the Item Added event handler.
Replace [SubfolderName] with the actual name of the subfolder created inside layouts directory in the previous step by Visual Studio. This is by default set to the same name as that of project.
The code inside the Item Added event receiver, first checks to make sure that, cancellation is done only for desired time slot. As DateTime.Hour is in 24 hours format, its a very easy check. The value 17 in 24 hour format equates to 6 p.m.
Next, the property Status is used. Its actually of type SPEventRecieverStatus, which in this case sets to CancelWithRedirectUrl. This will make sure to cancel the event and then redirect to a specific URL. Another property RedirectUrl is set to the actual URL , which is the URL of the page which will be displayed when event is cancelled.
Once all of this is done, press F5. This will build and deploy the solution.
In order to do a test, make sure that current time on the machine where SharePoint 2010 is installed is between 9am to 5pm, otherwise logic in the event handler to display custom page will be not executed due to the time interval check .Finally browse to portal, and open any document library and try to upload a document, the custom page should be displayed as shown below. Close the dialog page, and view the document library, notice that the document was not added to the document library.
This show how easy is to make a redirect to a custom page, by using a new enumeration value in SharePoint 2010 Object Model.
Most Popular Stories
- 1 Use jQuery to Kill Spell Checker in SharePoint Lists
- 2 Solve Item-Level Permission Performance Problems in SharePoint
- 3 Leveraging SharePoint as a Document Management System
- 4 Building SharePoint Suggestion Boxes and Soliciting Anonymous Feedback
- 5 Provide SharePoint Single Sign-On with Active Directory Federation Services
- 1 Building SharePoint Suggestion Boxes and Soliciting Anonymous Feedback
- 2 Leveraging SharePoint as a Document Management System
- 3 Solve Item-Level Permission Performance Problems in SharePoint
- 4 Provide SharePoint Single Sign-On with Active Directory Federation Services
- 5 SharePoint 2010 Makes the Link to LINQ
- 6 Using REST to Add and Delete List Items in SharePoint 2010
- 7 Developing SharePoint Solutions in Visual Studio Using WSPBuilder

While Java helps in fulfilling the promise of "write once, use anywhere", there are practical concerns developers need to address in developing their code, whether it's porting from another language, working in the best IDE or optimizing for today's multi-core computing environments. This eBook will help you in understanding these issues and how you can get the most out of your Java code.