?
Solved

folder creation in sub folder of "Shared Document" library

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

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

Last week I faced a strange issue recently, i have deployed SharePoint 2003 servers for one project and one of the requirements was to open SharePoint site from same server. when i was trying to open site from the same server i was getting authentic…
When installing SharePoint 2010 RTM I came across a strange error, I was getting timeouts during the installation. I searched the web and found the best solution to be found here (http://social.msdn.microsoft.com/Forums/en-US/sharepoint2010genera…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

801 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