[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

folder creation in sub folder of "Shared Document" library

Posted on 2010-09-13
3
Medium Priority
?
977 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

I used to be SharePoint evangelist in our company, so my Outlook always full of questions about how to do this, or where I can find that. One day I found such an email with the following question: "how to attach 3-State workflow (one of the workflow…
Summary In SharePoint 2010 it is easy to create custom color themes to jazz up a site. Theme colors can also be created in PowerPoint 2010 with a few clicks. But how do the chosen colors actually look in the SharePoint site? The attached PowerPoint…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

649 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