Sharepoint 2010 SharePoint 2010在资源管理器视图中上载时重命名文档失败
我正在尝试在SharePoint 2010中实现自定义,以便在将文档上载到库时,更改文件名以在名称中包含文档ID。(我知道人们不应该再担心文件名了,但我们有很多已经命名的遗留文件和喜欢本地副本的用户) 我能够在ItemAdded事件上实现自定义事件接收器,该事件通过在文件名之前添加文档ID来重命名文件。这可以从web上传正常工作 问题在于浏览器视图。当我尝试在Explorer视图中使用WebDAV添加该文件时,我得到了该文件的两个副本。似乎当一个文件通过网络上传时,触发的事件是Sharepoint 2010 SharePoint 2010在资源管理器视图中上载时重命名文档失败,sharepoint-2010,Sharepoint 2010,我正在尝试在SharePoint 2010中实现自定义,以便在将文档上载到库时,更改文件名以在名称中包含文档ID。(我知道人们不应该再担心文件名了,但我们有很多已经命名的遗留文件和喜欢本地副本的用户) 我能够在ItemAdded事件上实现自定义事件接收器,该事件通过在文件名之前添加文档ID来重命名文件。这可以从web上传正常工作 问题在于浏览器视图。当我尝试在Explorer视图中使用WebDAV添加该文件时,我得到了该文件的两个副本。似乎当一个文件通过网络上传时,触发的事件是 项目添加 添加项
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
}
}
}
}
希望这能帮助其他人解决同样的问题。是的,在工作流中处理这一问题似乎是最好的选择。我已经用我的代码添加了一个答案,但是我很感谢你的建议。它肯定会为其他人带来便利:-)是的,在工作流中处理这一点似乎是最好的选择。我已经用我的代码添加了一个答案,但是我很感谢你的建议。它肯定会为其他人带来便利:-)