我在使用客户端对象模型在文档库中创建文件时遇到了困难。我的自定义Visual Studio 2010工作流程在创建文件的列表项后没有检测到我所做的更新。
我想了解基础设施,以回答一些可能的问题:
以下是Web服务正在执行的操作的示例。它在IIS中以Business Intelligence用户身份运行。我已经添加了一些评论,说明我预期工作流会对哪些操作做出适当的响应。
Using client As New ClientContext(My.Settings.SharePointSiteURL)
// Pre-processing to determine appropriate user ID values for columns
Dim fci As New FileCreationInformation() With {
.Content = IO.File.ReadAllBytes(storagePath),
.Overwrite = True,
.Url = String.Format("{0}/{1}", theList.RootFolder.ServerRelativeUrl, theFileName)
}
Dim theFile As Microsoft.SharePoint.Client.File = theList.RootFolder.Files.Add(fci)
// Expecting the workflow to be activated here
client.ExecuteQuery()
theFile.ListItemAllFields("Project_x0020_Manager") = pmId
theFile.ListItemAllFields("Project_x0020_Accountant") = paId
theFile.ListItemAllFields.Update()
// Expecting the onWorkflowItemChanged activity to be invoked here
client.ExecuteQuery()
End Using
当上载文件并继续等待来自SharePoint的更改事件时,工作流会激活,但该事件永远不会作为Web服务操作的直接结果而到达。我可以手动修改项目并成功继续。
使用可能会阻止这些事件正常触发的客户端对象模型时是否需要考虑?
答案 0 :(得分:0)
看起来像一些奇怪的种族情况。我能用部分示例代码部分重现您的问题:
using (var client = new ClientContext(ConfigurationManager.AppSettings["Site"]))
{
client.Load(client.Site);
client.Load(client.Site.RootWeb);
var list = client.Site.RootWeb.Lists.GetByTitle("Shared Documents");
client.Load(list);
client.Load(list.RootFolder);
client.ExecuteQuery();
var fci = new FileCreationInformation()
{
Content = File.ReadAllBytes(ConfigurationManager.AppSettings["File"]),
Overwrite = true,
Url = list.RootFolder.ServerRelativeUrl + "/" + "file.xml"
};
var file = list.RootFolder.Files.Add(fci);
client.ExecuteQuery();
//If following 3 lines are commented out, problem you described may or may not occur. I wasn't able to run into problems, when i loaded file and list item before.
//client.Load(file);
//client.Load(file.ListItemAllFields);
//client.ExecuteQuery();
//Problem also doesn't occur, when i put here
//System.Threading.Thread.Sleep(1000);
//If code just runs here without delay, sometimes i run into issue you described.
var itm = file.ListItemAllFields;
itm["SampleColumn"] = "Test content!";
itm.Update();
client.ExecuteQuery();
}
和工作流程:
public Workflow1()
{
InitializeComponent();
}
public Guid workflowId = default(System.Guid);
public SPWorkflowActivationProperties workflowProperties = new SPWorkflowActivationProperties();
private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e)
{
var comment = "Workflow started!, item SampleColumn is: " +
workflowProperties.Item["SampleColumn"];
SPWorkflow.CreateHistoryEvent(workflowProperties.Web, WorkflowInstanceId, 0, workflowProperties.Web.CurrentUser, new TimeSpan(), "Update", comment, string.Empty);
}
private void onWorkflowItemChanged1_Invoked(object sender, ExternalDataEventArgs e)
{
var comment = "Workflow continous!, item Title is: " + workflowProperties.Item["SampleColumn"];
SPWorkflow.CreateHistoryEvent(workflowProperties.Web, WorkflowInstanceId, 0, workflowProperties.Web.CurrentUser, new TimeSpan(), "Update", comment, string.Empty);
}
工作流程本身
如果你有不同的东西,请告诉我。我在使用在SharePoint库上运行的声明性工作流时遇到了一些问题,而且大部分时间我都找不到好的解决方案。