没有名为 - Sharepoint事件处理程序的Web

时间:2010-04-04 07:28:44

标签: sharepoint document event-handling create-directory

我使用功能(网络级别范围)激活了以下代码。现在,当我向任何文档库添加项目时,它应该创建一个文件夹“”。

没有创建文件夹,也没有给出错误?任何人都可以看到发生了什么?我从日志文件中得到以下内容。我在谷歌找到了类似的代码所以我有点疑惑为什么不在我的环境中工作?

由于

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".

2 个答案:

答案 0 :(得分:1)

我看到两个主要问题:

  • SPContext.Current.Web.Url是网站的网址,而非列表。
  • SPList有一个RootFolder属性,可能比ToString()
  • 更合适

答案 1 :(得分:0)

SPContext.Current - 至少在我的经验中 - 由于某种原因在事件监听器中为null;相反,通过SPItemEventProperties参数中的相关属性获取当前的SPWeb和SPSite(并且不要在“使用”中使用它们,因为这样可以将它们用于以后的处理)