使用 Sharepoint 事件接​​收器在文档库中创建文件夹 [英] Create a folder in document library using Sharepoint event receiver

查看:57
本文介绍了使用 Sharepoint 事件接​​收器在文档库中创建文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码在我的文档库中创建一个文件夹.事件被触发并执行到我的代码的最后一行,没有任何问题.但是,该文件夹未在我的文档库中创建或列出.

I am using the following code to create a folder inside my document library. The event get triggered and executed till the last line of my code without any issues. However the folder is not getting created or listed in my document library.

public override void ItemAdded(SPItemEventProperties properties)
{
    base.ItemAdded(properties);        

    string strDashListRoot = "http://win-hmpjltdbh5q:37642";
    using (SPSite site = new SPSite(strDashListRoot))
    {
        using (SPWeb web = site.OpenWeb())
        {
            web.AllowUnsafeUpdates = true;                    

            SPList spl = web.Lists["client_documents"];
            spl.Items.Add("", SPFileSystemObjectType.Folder, "Helllworld");
            spl.Update();
            web.AllowUnsafeUpdates = false;
        }
    }           
}

推荐答案

您需要

var i = spl.Items.Add("", SPFileSystemObjectType.Folder, "Helllworld");
i.Update(); 

代替

spl.Items.Add("", SPFileSystemObjectType.Folder, "Helllworld");
spl.Update();

(假设您的 Add 调用没问题 - 对我来说看起来没问题)

(assuming your Add call is fine - it looks OK to me)

(另外,您确定需要 AllowUnsafeUpdates 处理吗?当您在 ItemAdded 处理程序中时,我不认为它是必要的.)

(Also, are you sure you need the AllowUnsafeUpdates handling? I wouldn't have expected it to be necessary when you're in an ItemAdded handler.)

这篇关于使用 Sharepoint 事件接​​收器在文档库中创建文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆