• Home
  • About
Subscribe: Posts | Comments | E-mail
  • SharePointTopics on Microsoft SharePoint Technology
  • Silverlight, WPFSilverlight, Windows Presentation Foundation
  • MiscellaneousRandom bits and rants

Rouslan Grabar on NET, SharePoint, SilverLight, WPF and other technology related topics

Posted on October 19, 2009 - by Rouslan Grabar

How to allow only Folder items to be created in the List root folder

SharePoint


Sometimes you need to prohibit creation of list items in the root folder of the list. For example,  you invented some pretty looking,  folder-based, issue cataloguing system, but end users create issues in list’s root folder no matter how hard you beg them not to.

Below you will find the code that looks into HttpContext for a “RootFolder” and “Type” parameters and makes use of SPItemEventProperties.Cancel property.

public class IssueItemEventReceiver : SPItemEventReceiver
{
	private HttpContext _current;

	public IssueItemEventReceiver()
	{
		_current = HttpContext.Current;
	}
	public override void ItemAdding(SPItemEventProperties properties)
	{
		using (SPSite site = new SPSite(properties.SiteId))
		{
			using (SPWeb web = site.OpenWeb(properties.RelativeWebUrl))
			{
				SPList list = web.Lists["Issues"];
				string rootRelUrl = string.Format("{0}/{1}",
						properties.RelativeWebUrl,
						list.RootFolder);

				bool isFolder = (_current.Request.Params["Type"] != null
										&& _current.Request.Params["Type"] == "1");
				bool isInRoot = (_current.Request.Params["RootFolder"] == rootRelUrl);
				properties.Cancel = !(isFolder && isInRoot);
				//// here you can redirect to your very own page in _layouts folder
				//if (properties.Cancel)
				//{
				//	SPUtility.Redirect("myFeatureFolderInLayoutsFolder/MyCustomErrorPage.aspx",
				//				SPRedirectFlags.RelativeToLayoutsPage | SPRedirectFlags.Trusted,
				//				_current);
				//}
			}
		}
	}
}
This entry was posted on Monday, October 19th, 2009 at 3:31 PM and is filed under SharePoint. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

0 Comments

We'd love to hear yours!



Leave a Reply


Here's your chance to speak.

Click here to cancel reply.

  1. Name (required)

    Mail (required)

    Website

    Message

  • Recent Posts

    • SharePoint 2010: Проектирование списков и схем [techdays.ru]
    • Доклад по PerformancePoint Server 2007 на сайте TechDays.ru
    • How to allow only Folder items to be created in the List root folder
    • Move list item into a subfolder in the same list
    • Краткий обзор возможностей SharePoint 2010 для конечных пользователей
  • Tags

    Для новичков Customization Developer Utility Fileds For Beginners IIS mac os x Misc MOSS MSDN photosynth Powershell Russian Screencast SharePoint SharePoint 2010 SharePoint Designer Silverlight, WPF Snippet SPItemEventReceiver techdays timer job Toolbox tricks troubleshooting Virtualisation VSeWSS wcf web service Windows windows authentication WPF WSS
  • Blogroll

    • My personal journal in Russian.
    • Picture Downloader Software
    • Russian SharePoint Community
  • Archives

    • March 2010
    • November 2009
    • October 2009
    • July 2009
    • May 2009
    • April 2009
    • March 2009
© 2009 Rouslan Grabar. All Rights Reserved.