Solved

folder creation in sub folder of "Shared Document" library

Posted on 2010-09-13
3
949 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
  • 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

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…
Microsoft SharePoint Foundation 2010 and Microsoft SharePoint Server 2010 do not offer the option to configure the location of the SharePoint diagnostic trace log files during installation.  This can, however, be configured through Central Administr…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

810 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