Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Events 自定义事件接收器-复制到文件夹_Events_Sharepoint 2010_Event Handling - Fatal编程技术网

Events 自定义事件接收器-复制到文件夹

Events 自定义事件接收器-复制到文件夹,events,sharepoint-2010,event-handling,Events,Sharepoint 2010,Event Handling,我正在编写一个自定义事件接收器。基本流程如下: 文档被添加到库中 根据文档的元数据,我们检查另一个文档库中是否存在文件夹 如果文件夹不存在,则会创建该文件夹 新添加的文档将复制到另一个文档库中的文件夹中 我已经做到了这一点,在添加新添加的文件时,我可以将它们从一个文档库复制到另一个文档库。但是,我不知道如何复制到文档库中的特定目录(按名称)。任何帮助都会得到很大的帮助 以下是我目前的代码: SPFile sourceFile = properties.ListItem.File; SPFile

我正在编写一个自定义事件接收器。基本流程如下:

  • 文档被添加到库中

  • 根据文档的元数据,我们检查另一个文档库中是否存在文件夹

  • 如果文件夹不存在,则会创建该文件夹

  • 新添加的文档将复制到另一个文档库中的文件夹中

  • 我已经做到了这一点,在添加新添加的文件时,我可以将它们从一个文档库复制到另一个文档库。但是,我不知道如何复制到文档库中的特定目录(按名称)。任何帮助都会得到很大的帮助

    以下是我目前的代码:

    SPFile sourceFile = properties.ListItem.File;
    SPFile destFile; // Copy file from source library to destination         
    using (Stream stream = sourceFile.OpenBinaryStream())
    {
        var destLib = (SPDocumentLibrary) properties.ListItem.Web.Lists[listName];
        destFile = destLib.RootFolder.Files.Add(sourceFile.Name, stream);
        stream.Close();
    } 
    // Update item properties         
    SPListItem destItem = destFile.Item;
    SPListItem sourceItem = sourceFile.Item;
    // Copy meta data
    destItem["Title"] = sourceItem["Title"];
    //...        
    //... destItem["FieldX"] = sourceItem["FieldX"];        
    //...         
    destItem.UpdateOverwriteVersion();
    
    答复

    //Ensure folder here 
    
    var destFolder = destLib.RootFolder.SubFolders["name"]; 
    
    destFile = destFolder.Files.Add(sourceFile.Name, stream);