locked
There is no Web named RRS feed

  • Question

  • I activated following code with feature (web level scope). Now when i add an item to any document library it should create a folder "".
    No folder is created and no error is given either. can anyone see what's is going on? I got the following from the log file.

    Thanks


    using System;
    using System.Collections.Generic;
    using System.Text;
    using Microsoft.SharePoint;

    namespace AddaFolder
    {
        class clAddaFolder : SPItemEventReceiver
        {
            public override void ItemAdded(SPItemEventProperties properties)
            {
                base.ItemAdded(properties);
                using (SPSite currentSite = new SPSite(SPContext.Current.Site.Url))
                using (SPWeb currentWeb = currentSite.OpenWeb(SPContext.Current.Web.Url))
                {
                    try
                    {
                    //SPListTemplateCollection coll = currentWeb.ListTemplates;

                    //Get the current document library link
                    SPList newList = currentWeb.GetList(SPContext.Current.Web.Url);
                        //.Site.Url);
                    //newList = currentWeb.Lists.Add("My TEST Folder",SPFileSystemObjectType.Folder);
                    //newList.Lists.Items.Add("My TEST Folder", SPFileSystemObjectType.Folder);
                    //newList.Update();              

                    SPListItem newListItem;
                    //newListItem = newList.Folders.Add("", SPFileSystemObjectType.Folder, "My Test Folder");
                    newListItem = newList.Folders.Add(newList.ToString(), SPFileSystemObjectType.Folder, "My Test Folder");
                    newListItem.Update();             
                    }
                    catch (SPException spEx)
                    {
                        throw spEx;               
                    }

                }

            }
        }
    }




    04/03/2010 17:52:44.25     w3wp.exe (0x00C0)                           0x0C88    Windows SharePoint Services       General                           8kh7    High        There is no Web named "/sites/myDevSiteColl/myDevWeb/Shared Documents/Forms/AllItems.aspx".     
    04/03/2010 17:52:44.26     w3wp.exe (0x00C0)                           0x0C88    Windows SharePoint Services       General                           8kh7    High        There is no Web named "/sites/myDevSiteColl/myDevWeb/My TEST Doc Library/Forms/AllItems.aspx".     
    04/03/2010 17:52:44.27     w3wp.exe (0x00C0)                           0x0C88    Windows SharePoint Services       General                           8kh7    High        There is no Web named "/sites/myDevSiteColl/myDevWeb/Lists/Calendar/calendar.aspx".     
    04/03/2010 17:52:44.29     w3wp.exe (0x00C0)                           0x0C88    Windows SharePoint Services       General                           8kh7    High        There is no Web named "/sites/myDevSiteColl/myDevWeb/Lists/Tasks/AllItems.aspx".     
    04/03/2010 17:52:44.30     w3wp.exe (0x00C0)                           0x0C88    Windows SharePoint Services       General                           8kh7    High        There is no Web named "/sites/myDevSiteColl/myDevWeb/Lists/Team Discussion/AllItems.aspx".     
    04/03/2010 17:52:44.31     w3wp.exe (0x00C0)                           0x0C88    Windows SharePoint Services       General                           8kh7    High        There is no Web named "/sites/myDevSiteColl/myDevWeb/Shared Documents/Forms/AllItems.aspx".     
    04/03/2010 17:52:44.32     w3wp.exe (0x00C0)                           0x0C88    Windows SharePoint Services       General                           8kh7    High        There is no Web named "/sites/myDevSiteColl/myDevWeb/My TEST Doc Library/Forms/AllItems.aspx".     
    04/03/2010 17:52:44.34     w3wp.exe (0x00C0)                           0x0C88    Windows SharePoint Services       General                           8kh7    High        There is no Web named "/sites/myDevSiteColl/myDevWeb/Lists/Calendar/calendar.aspx".     
    04/03/2010 17:52:44.35     w3wp.exe (0x00C0)                           0x0C88    Windows SharePoint Services       General                           8kh7    High        There is no Web named "/sites/myDevSiteColl/myDevWeb/Lists/Tasks/AllItems.aspx".     
    04/03/2010 17:52:44.36     w3wp.exe (0x00C0)                           0x0C88    Windows SharePoint Services       General                           8kh7    High        There is no Web named "/sites/myDevSiteColl/myDevWeb/Lists/Team Discussion/AllItems.aspx".     
    04/03/2010 17:52:51.33     w3wp.exe (0x00C0)                           0x0C88    Windows SharePoint Services       General                           8kh7    High        There is no Web named "/sites/myDevSiteColl/myDevWeb/Shared Documents/Forms/AllItems.aspx".     
    04/03/2010 17:52:51.34     w3wp.exe (0x00C0)                           0x0C88    Windows SharePoint Services       General                           8kh7    High        There is no Web named "/sites/myDevSiteColl/myDevWeb/My TEST Doc Library/Forms/AllItems.aspx".     
    04/03/2010 17:52:51.35     w3wp.exe (0x00C0)                           0x0C88    Windows SharePoint Services       General                           8kh7    High        There is no Web named "/sites/myDevSiteColl/myDevWeb/Lists/Calendar/calendar.aspx".     
    04/03/2010 17:52:51.37     w3wp.exe (0x00C0)                           0x0C88    Windows SharePoint Services       General                           8kh7    High        There is no Web named "/sites/myDevSiteColl/myDevWeb/Lists/Tasks/AllItems.aspx".     
    04/03/2010 17:52:51.38     w3wp.exe (0x00C0)                           0x0C88    Windows SharePoint Services       General                           8kh7    High        There is no Web named "/sites/myDevSiteColl/myDevWeb/Lists/Team Discussion/AllItems.aspx".     
    04/03/2010 17:52:51.39     w3wp.exe (0x00C0)                           0x0C88    Windows SharePoint Services       General                           8kh7    High        There is no Web named "/sites/myDevSiteColl/myDevWeb/Shared Documents/Forms/AllItems.aspx".     
    04/03/2010 17:52:51.40     w3wp.exe (0x00C0)                           0x0C88    Windows SharePoint Services       General                           8kh7    High        There is no Web named "/sites/myDevSiteColl/myDevWeb/My TEST Doc Library/Forms/AllItems.aspx".     
    04/03/2010 17:52:51.41     w3wp.exe (0x00C0)                           0x0C88    Windows SharePoint Services       General                           8kh7    High        There is no Web named "/sites/myDevSiteColl/myDevWeb/Lists/Calendar/calendar.aspx".     
    04/03/2010 17:52:51.43     w3wp.exe (0x00C0)                           0x0C88    Windows SharePoint Services       General                           8kh7    High        There is no Web named "/sites/myDevSiteColl/myDevWeb/Lists/Tasks/AllItems.aspx".     
    04/03/2010 17:52:51.44     w3wp.exe (0x00C0)                           0x0C88    Windows SharePoint Services       General                           8kh7    High        There is no Web named "/sites/myDevSiteColl/myDevWeb/Lists/Team Discussion/AllItems.aspx".     
    04/03/2010 17:53:02.69     w3wp.exe (0x00C0)                           0x0C88    Windows SharePoint Services       General                           8kh7    High        There is no Web named "/sites/myDevSiteColl/myDevWeb/Shared Documents/Forms/AllItems.aspx".     
    04/03/2010 17:53:02.71     w3wp.exe (0x00C0)                           0x0C88    Windows SharePoint Services       General                           8kh7    High        There is no Web named "/sites/myDevSiteColl/myDevWeb/My TEST Doc Library/Forms/AllItems.aspx".     
    04/03/2010 17:53:02.72     w3wp.exe (0x00C0)                           0x0C88    Windows SharePoint Services       General                           8kh7    High        There is no Web named "/sites/myDevSiteColl/myDevWeb/Lists/Calendar/calendar.aspx".     
    04/03/2010 17:53:02.73     w3wp.exe (0x00C0)                           0x0C88    Windows SharePoint Services       General                           8kh7    High        There is no Web named "/sites/myDevSiteColl/myDevWeb/Lists/Tasks/AllItems.aspx".     
    04/03/2010 17:53:02.74     w3wp.exe (0x00C0)                           0x0C88    Windows SharePoint Services       General                           8kh7    High        There is no Web named "/sites/myDevSiteColl/myDevWeb/Lists/Team Discussion/AllItems.aspx".     
    04/03/2010 17:53:02.75     w3wp.exe (0x00C0)                           0x0C88    Windows SharePoint Services       General                           8kh7    High        There is no Web named "/sites/myDevSiteColl/myDevWeb/Shared Documents/Forms/AllItems.aspx".     
    04/03/2010 17:53:02.76     w3wp.exe (0x00C0)                           0x0C88    Windows SharePoint Services       General                           8kh7    High        There is no Web named "/sites/myDevSiteColl/myDevWeb/My TEST Doc Library/Forms/AllItems.aspx".     
    04/03/2010 17:53:02.77     w3wp.exe (0x00C0)                           0x0C88    Windows SharePoint Services       General                           8kh7    High        There is no Web named "/sites/myDevSiteColl/myDevWeb/Lists/Calendar/calendar.aspx".     
    04/03/2010 17:53:02.78     w3wp.exe (0x00C0)                           0x0C88    Windows SharePoint Services       General                           8kh7    High        There is no Web named "/sites/myDevSiteColl/myDevWeb/Lists/Tasks/AllItems.aspx".     
    04/03/2010 17:53:02.79     w3wp.exe (0x00C0)                           0x0C88    Windows SharePoint Services       General                           8kh7    High        There is no Web named "/sites/myDevSiteColl/myDevWeb/Lists/Team Discussion/AllItems.aspx".
    Saturday, April 3, 2010 11:04 PM

Answers

All replies

  • Hi,

    Can you edit your code and add some code like this:

    SPList newList = currentWeb.GetList(SPContext.Current.Web.Url);
    SPListItem newFolder = newList.Items.Add();
    newFolder.ContentType = currentWeb.AvailableContentTypes("0x0120");
    newFolder.Title = "My New Folder";                
    newListItem.Update();

    Let me know
                

    BR, PM
    Sunday, April 4, 2010 3:29 AM
  • or if the above code does not work then:

    SPFolderCollection folders = (SPFolderCollection)newList.Folders;
    SPFolder newFolder = folders.Add("My New Folder");
    newList.Update();

     


    BR, PM
    Sunday, April 4, 2010 3:32 AM
  • Prasanjit,

    The tried your 2nd suggestion first. and it's giving error on this line SPFolderCollection folders = (SPFolderCollection)newList.Folders;.

     

    Error    1    Cannot convert type 'Microsoft.SharePoint.SPListItemCollection' to 'Microsoft.SharePoint.SPFolderCollection'    C:\myProject\EH_CreateFolder.cs

    Sunday, April 4, 2010 3:53 AM
  • Prasanjit,

    I tried your 1st suggestion. and it's giving me errors on 2 lines.

    newFolder.ContentType = currentWeb.AvailableContentTypes("0x0120");

    Error    1    'Microsoft.SharePoint.SPWeb.AvailableContentTypes' is a 'property' but is used like a 'method'

     

    newFolder.Title = "My New Folder";

    Error    3    Property or indexer 'Microsoft.SharePoint.SPListItem.Title' cannot be assigned to -- it is read only

    Sunday, April 4, 2010 3:58 AM
  • OOPS & double OOPS..

    Try once more with this:

    newList.RootFolder.SubFolders.Add(“mynewFolder”);

    newList.Update();

    and check this link also for your reference: http://geekswithblogs.net/CalinTatar/archive/2009/06/07/automatically-add-sharepoint-subfolders-when-adding-a-new-folder-content.aspx


    BR, PM
    Sunday, April 4, 2010 4:13 AM
  • Actually the idea is to create a folder when end user upload a file to a document library. Now this document library can be anywhere under the web. (not trying to create subfolder).

     

    I tried your last suggestion and still not working. hmm

    Sunday, April 4, 2010 5:52 AM
  • You can use SPListEventProperties.Web Property(http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splisteventproperties.web.aspx) to get a reference to the Web site that contains the list that is affected by the event.

    You can use SPListEventProperties.List Property (http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splisteventproperties.list.aspx) to get a reference to the list that is affected by the event.

    -----------------------SAMPLE CODE--------------------------

    SPDocumentLibrary docLib = properties.List as SPDocumentLibrary;
    SPFolderCollection folders = docLib.RootFolder;
    folder.Add("newFolder");

    -----------------------SAMPLE CODE--------------------------

     


    Cogito, ergo sum.
    Tuesday, April 6, 2010 1:56 AM