在SharePoint Server 2010中,我有一个文档库,我想在每次创建文件夹时创建子文件夹,我有一个代码片段但它不起作用,我试图调试但事件没有触发,可能任何人请帮助我,这是我的代码:
public class EventReceiver1 : SPItemEventReceiver
{
/// <summary>
/// An item was added.
/// </summary>
private string[] subFolders = new string[] { "sub-folder1", "sub-folder2", "sub folder3" };
public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdded(properties);
SPWeb web = properties.OpenWeb();
SPDocumentLibrary ProductsLibrary = (SPDocumentLibrary)web.Lists[properties.ListId];
if (properties.ListItem.ContentType.Name.ToLower() == "new content type" && properties.ListItem.Folder.ParentFolder.ToString() == ProductsLibrary.RootFolder.ToString())
{
string Url = properties.ListItem.ParentList.RootFolder.ServerRelativeUrl.ToString();
SPFolder libFolder = ProductsLibrary.RootFolder.SubFolders[properties.ListItem.Name];
string newFolderUrl = (web.Url + "/" + libFolder.ToString());
foreach (string subfolder in subFolders)
{
SPListItem newSubFolder = ProductsLibrary.Items.Add(newFolderUrl, SPFileSystemObjectType.Folder, subfolder);
newSubFolder.Update();
}
}
}
}
谢谢
答案 0 :(得分:0)
解决方案是打开elements.xml并替换 使用和代码将完美运行。
答案 1 :(得分:0)
确保
如果您没有按照上述步骤
,事件不会触发