Solved

folder creation in sub folder of "Shared Document" library

Posted on 2010-09-13
3
960 Views
Last Modified: 2012-05-10
Hi, I have following code where I am able to create folder in "Shared Document" library when item is added in list but i want that folder should get created in already exit folder like I have already "Test " folder in library , in this folder should get created sub folders of title of list item added in list which getting created in root level of library,

please check my code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.SharePoint;
using System.Configuration;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.Navigation;
namespace ABC_EventHandler
{
    public class CreateFolder : Microsoft.SharePoint.SPItemEventReceiver
    {
        public override void ItemAdded(SPItemEventProperties properties)
        {
            try
            {
                this.DisableEventFiring();
                string sUrlOfWikiPage = string.Empty;
                string sUrlOfNewFolder = string.Empty;
                string sSubsiteRUL = string.Empty;
                string sCurrentItemTitle = properties.ListItem["Title"].ToString();
                string sDocLibName = "Shared Documents";
                string sTRListID = "ABC Status";
                this.EnableEventFiring();

//Since the event handler is attached based on base ID of a list, this event handler will be attached to all custom lists
//To prevent it from being executed on other custom lists (which will create an error), the following validation is done.

                if (sTRListID.ToUpper().Equals(properties.ListTitle.ToString().ToUpper()))
                {
                    //Create the Folder
                    sUrlOfNewFolder = CreateFolder(properties.ListItem.Web, sDocLibName, sCurrentItemTitle);

                                       
                   
                    properties.ListItem.Update();
                    properties.ListItem.UpdateOverwriteVersion();
                  
                }
            }
            catch(Exception excGeneral)
            {
               LogError(properties.ListItem.Web, "ItemAdded -->" + excGeneral.Message + "-->" + excGeneral.InnerException.ToString() + "-->" + excGeneral.StackTrace);
            }
        }
         public string CreateFolder(SPWeb oWeb, string sDocLibName, string sTitle)
        {
            try
            {
                SPDocumentLibrary docLib = (SPDocumentLibrary)oWeb.Lists[sDocLibName];
                SPFolder DLrootFolder = docLib.RootFolder;
                SPFolder oNewFolder = DLrootFolder.SubFolders.Add(oWeb.Url + "/" + sDocLibName + "/" + sTitle);
                return oWeb.Url + "/" + oNewFolder.Url.ToString();
            }
            catch (Exception excCreateFolder)
            {
                LogError(oWeb, "CreateFolder -->" + excCreateFolder.Message + "-->" + excCreateFolder.InnerException.ToString() + "-->" + excCreateFolder.StackTrace);
                throw excCreateFolder;
            }
        }

        /// <summary>
        /// This method logs any error(s) that happens within the event handler into a list
        /// Any exception that happens within this method is not handled and throw to the system to handle.
        /// </summary>
        /// <param name="oWeb">The SPWeb object which holds the "Errors List"</param>
        /// <param name="sErrorMessage">The detailed error</param>
        public void LogError(SPWeb oWeb,  string sErrorMessage)
        {
            try
            {
                string sErrorsListName = ConfigurationSettings.AppSettings["ErrorsList"].ToString();
                SPList oErrorsList = oWeb.Lists[sErrorsListName];
                SPListItem oNewItem = oErrorsList.Items.Add();
                oNewItem["Title"] = sErrorMessage;
                oNewItem.Update();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    
        }


        }

Open in new window

0
Comment
Question by:sandipkharde
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 7

Expert Comment

by:EagleUK
ID: 33675131
A little more information helps people help you solve your problem. What symptoms are you experiencing? When do the errors occur?
0
 
LVL 8

Accepted Solution

by:
sandipkharde earned 0 total points
ID: 33683587
solved issue by playing with code....there was issue with concatenation of wording when item is added in lis.
0
 
LVL 8

Author Closing Comment

by:sandipkharde
ID: 33683595
.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Work Over Net is a new and very powerful collaboration product. With its new easy interface it is becoming very competitive to other similar products like webex and office interactive. WON 2010 have the standard business tools needed for multi-offic…
We had a requirement to extract data from a SharePoint 2010 Customer List into a CSV file and then place the CSV file into a directory on the network so that the file could be consumed by an AS400 system. I will share in Part 1 how to Extract the Da…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question