Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/151.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
Sharepoint 2010 SharePoint 2010在资源管理器视图中上载时重命名文档失败_Sharepoint 2010 - Fatal编程技术网

Sharepoint 2010 SharePoint 2010在资源管理器视图中上载时重命名文档失败

Sharepoint 2010 SharePoint 2010在资源管理器视图中上载时重命名文档失败,sharepoint-2010,Sharepoint 2010,我正在尝试在SharePoint 2010中实现自定义,以便在将文档上载到库时,更改文件名以在名称中包含文档ID。(我知道人们不应该再担心文件名了,但我们有很多已经命名的遗留文件和喜欢本地副本的用户) 我能够在ItemAdded事件上实现自定义事件接收器,该事件通过在文件名之前添加文档ID来重命名文件。这可以从web上传正常工作 问题在于浏览器视图。当我尝试在Explorer视图中使用WebDAV添加该文件时,我得到了该文件的两个副本。似乎当一个文件通过网络上传时,触发的事件是 项目添加 添加项

我正在尝试在SharePoint 2010中实现自定义,以便在将文档上载到库时,更改文件名以在名称中包含文档ID。(我知道人们不应该再担心文件名了,但我们有很多已经命名的遗留文件和喜欢本地副本的用户)

我能够在ItemAdded事件上实现自定义事件接收器,该事件通过在文件名之前添加文档ID来重命名文件。这可以从web上传正常工作

问题在于浏览器视图。当我尝试在Explorer视图中使用WebDAV添加该文件时,我得到了该文件的两个副本。似乎当一个文件通过网络上传时,触发的事件是

  • 项目添加
  • 添加项目
  • 但是,当我将文件复制/粘贴到资源管理器视图时,我会看到以下事件:

  • 项目添加
  • 添加项目
  • 项目添加
  • 添加项目
  • 项目更新
  • 项目更新
  • 结果是我有两个不同名称的文件(因为文档ID不同)

    我发现很多人在网上谈论这个问题(这是我找到的最好的文章)。有人有其他想法吗?在工作流中而不是在事件接收器中这样做是否更有意义?我可以改为使用计划作业,但如果文档名称在几分钟后更改,用户可能会感到困惑

    这是我的代码,在使用Web上载时效果很好,但在使用Explorer View时效果不佳:

    public override void ItemAdded(SPItemEventProperties properties)
    {
       try
       {
           SPListItem currentItem = properties.ListItem;
    
           if (currentItem["_dlc_DocId"] != null)
           {
           string docId = currentItem["_dlc_DocId"].ToString();
           if (!currentItem["BaseName"].ToString().StartsWith(docId))
           {
               EventFiringEnabled = false;
               currentItem["BaseName"] = docId + currentItem["BaseName"];
               currentItem.SystemUpdate();
               EventFiringEnabled = true;
           }
           }
       }
       catch (Exception ex)
       {
           //Probably should log an error here
       }            
       base.ItemAdded(properties);
    }
    

    我会选择工作流解决方案。。。国际海事组织有两种选择:

    1) 在文档库中创建一个布尔值,然后创建一个SPD工作流,该工作流在添加项目时启动,并将该字段设置为“已更改”或其他内容。然后在EventReceiver中检查该字段是否已设置


    2) 使用SPD工作流执行所有操作-像本例中那样更改标题应该没有问题。

    好吧,我会选择工作流解决方案。。。国际海事组织有两种选择:

    1) 在文档库中创建一个布尔值,然后创建一个SPD工作流,该工作流在添加项目时启动,并将该字段设置为“已更改”或其他内容。然后在EventReceiver中检查该字段是否已设置


    2) 使用SPD工作流执行所有操作-如本例中所示更改标题应该没有问题。

    我发现使用Visual Studio工作流可以让我最灵活地执行此操作。SharePoint Designer工作流将更简单,但更难部署到不同的网站和库

    在阅读了一些很好的文章之后,包括和,我已经想出了这个代码,这似乎是可行的。它启动工作流并等待文档不处于锁定状态,然后处理文件名

    工作流如下所示:

    下面是背后的代码:

    namespace ControlledDocuments.RenameWorkflow
    {
        public sealed partial class RenameWorkflow : SequentialWorkflowActivity
        {
            public RenameWorkflow()
            {
                InitializeComponent();
            }
    
            public Guid workflowId = default(System.Guid);
            public SPWorkflowActivationProperties workflowProperties = new SPWorkflowActivationProperties();
    
            Boolean continueWaiting = true;
    
    
            private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e)
            {
                CheckFileStatus();
            }
    
            private void whileActivity(object sender, ConditionalEventArgs e)
            {
                e.Result = continueWaiting;
            }
    
            private void onWorkflowItemChanged(object sender, ExternalDataEventArgs e)
            {
                CheckFileStatus();
            }
    
            private void CheckFileStatus()
            {
                if (workflowProperties.Item.File.LockType == SPFile.SPLockType.None)
                {
                    continueWaiting = false;
                }
            }
    
            private void renameFile(object sender, EventArgs e)
            {
                try
                {
                    SPListItem currentItem = workflowProperties.Item;
    
                    if (currentItem["_dlc_DocId"] != null)
                    {
                        string docId = currentItem["_dlc_DocId"].ToString();
                        if (!currentItem["BaseName"].ToString().StartsWith(docId))
                        {
                            currentItem["BaseName"] = docId + currentItem["BaseName"];
                            currentItem.SystemUpdate();
                        }
                    }
                }
                catch (Exception ex)
                {
                    //Should do something useful here
                }
            }
    
        }
    }
    

    如果其他人有同样的问题,希望这能帮助他们。

    我发现使用Visual Studio工作流可以让我最灵活地完成这项工作。SharePoint Designer工作流将更简单,但更难部署到不同的网站和库

    在阅读了一些很好的文章之后,包括和,我已经想出了这个代码,这似乎是可行的。它启动工作流并等待文档不处于锁定状态,然后处理文件名

    工作流如下所示:

    下面是背后的代码:

    namespace ControlledDocuments.RenameWorkflow
    {
        public sealed partial class RenameWorkflow : SequentialWorkflowActivity
        {
            public RenameWorkflow()
            {
                InitializeComponent();
            }
    
            public Guid workflowId = default(System.Guid);
            public SPWorkflowActivationProperties workflowProperties = new SPWorkflowActivationProperties();
    
            Boolean continueWaiting = true;
    
    
            private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e)
            {
                CheckFileStatus();
            }
    
            private void whileActivity(object sender, ConditionalEventArgs e)
            {
                e.Result = continueWaiting;
            }
    
            private void onWorkflowItemChanged(object sender, ExternalDataEventArgs e)
            {
                CheckFileStatus();
            }
    
            private void CheckFileStatus()
            {
                if (workflowProperties.Item.File.LockType == SPFile.SPLockType.None)
                {
                    continueWaiting = false;
                }
            }
    
            private void renameFile(object sender, EventArgs e)
            {
                try
                {
                    SPListItem currentItem = workflowProperties.Item;
    
                    if (currentItem["_dlc_DocId"] != null)
                    {
                        string docId = currentItem["_dlc_DocId"].ToString();
                        if (!currentItem["BaseName"].ToString().StartsWith(docId))
                        {
                            currentItem["BaseName"] = docId + currentItem["BaseName"];
                            currentItem.SystemUpdate();
                        }
                    }
                }
                catch (Exception ex)
                {
                    //Should do something useful here
                }
            }
    
        }
    }
    

    希望这能帮助其他人解决同样的问题。

    是的,在工作流中处理这一问题似乎是最好的选择。我已经用我的代码添加了一个答案,但是我很感谢你的建议。它肯定会为其他人带来便利:-)是的,在工作流中处理这一点似乎是最好的选择。我已经用我的代码添加了一个答案,但是我很感谢你的建议。它肯定会为其他人带来便利:-)