没有名为 - Sharepoint Event Hander 的网站

发布于 2024-08-27 10:29:10 字数 8872 浏览 3 评论 0原文

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

没有创建文件夹也没有报错?谁能看到发生了什么事吗?我从日志文件中得到以下内容。我在谷歌上发现了类似的代码,所以我有点困惑为什么在我的环境中不起作用?

感谢

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

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 is going on? I got the following from the log file. I found similar code all over google so I am kinda puzzled why is not working in my environment?

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;                
                }

            }

        }
    }
}

log file

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦里的微风 2024-09-03 10:29:10

我在那里看到两个主要问题:

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

I see two major problems there:

  • SPContext.Current.Web.Url is the url of a web, not a list.
  • SPList has a RootFolder property that would probably be more appropriate than ToString()
夜还是长夜 2024-09-03 10:29:10

SPContext.Current - 至少根据我的经验 - 由于某种原因在事件侦听器中为空;相反,通过 SPItemEventProperties 参数中的相关属性获取当前的 SPWeb 和 SPSite(并且不要在“using”中使用它们,因为这会使它们被丢弃以供以后处理)。

SPContext.Current - at least in my experience - is for some reason null in event listeners; instead, get at the current SPWeb and SPSite through the relevant properties in the SPItemEventProperties parameter (and do not use them in "using" since that would make them disposed for later processing).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文