Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Create folder event handler

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

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.

Share: 

 

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
http://sharepoint/dsi/itdept/intranet/itprojectsites/dsimarketing.


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  =
properties.OpenWeb().GetList("http://sharepoint/dsi/itdept/internal/dsimarketing\
/Lists/DSI%20Projects");
SPFieldLookupValue surveyvalue =
(SPFieldLookupValue)ItemUpdated.fields["Project
Name"].GetFieldValue((string)ItemUpdated["Project Name"]);
SPItem projectname = survey.Items[surveyvalue.LookupID];

if (properties.ListItem["Completed"] != 1)
{
SPSite _MySite = new
SPSite("http://sharepoint/dsi/itdept/itprojectssite/dsimarketing/");

SPWeb _MyWeb = _MySite.OpenWeb();



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

SPFolderCollection _MyFolders = _MyWeb.Folders;

_MyFolders.Add("http://sharepoint/dsi/itdept/internal/itprojects
site/dsimarketing/Project%20Photos/" + projectname + "/");

_MyDocLibrary.Update();


}

}
}
}

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

Check out the link below.

www.c-sharpcorner.com/.../EventHandler04292009070324AM\
/EventHandler.aspx

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.




Tagged: