Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Create folder event handler

  Asked By: Juana    Date: Jul 11    Category: Sharepoint    Views: 3194

I need to create an event handler that creates a folder in a picture library
when a survey is completed. The name of the folder should be the value of the
survey field "Project Name". I have never written event handlers before and was
hoping that someone could help me with the code for this.



4 Answers Found

Answer #1    Answered By: Eashan Nadkarni     Answered On: Jul 11

Here is my stab at the code  from the information I found on various sites. My
survey name is "DSI Projects", my picture  library is "Project Photos" and the
url where this lists are located is

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Sharepoint;

namespace Eventhandler_CreatePhotoFolder
public class AddPhotoFolder: SPItemEventReceiver
public override void ItemUpdated(SPItemEventProperties properties)
SPList survey  =
SPFieldLookupValue surveyvalue =
Name"].GetFieldValue((string)ItemUpdated["Project Name"]);
SPItem projectname = survey.Items[surveyvalue.LookupID];

if (properties.ListItem["Completed"] != 1)
SPSite _MySite = new

SPWeb _MyWeb = _MySite.OpenWeb();

SPDocumentLibrary _MyDocLibrary =
(SPDocumentLibrary)_MyWeb.Lists["Project Photos"];

SPFolderCollection _MyFolders = _MyWeb.Folders;

site/dsimarketing/Project%20Photos/" + projectname + "/");




Answer #2    Answered By: William Odom     Answered On: Jul 11

Check out the link below.


If you still have questions, let me know.

Answer #3    Answered By: Mia Scott     Answered On: Jul 11

This article only addresses when deleting an item. I'm not sure my code  is
right for adding a new folder  to a picture  library and using a field  from my
survey for the name of the folder.

Answer #4    Answered By: Kristian Chaney     Answered On: Jul 11

It was just a sample for showing the way to create  Event Handlers. In your
case, you might have to override ItemAdded event.

Didn't find what you were looking for? Find more on Create folder event handler Or get search suggestion and latest updates.