SharePoint 2013 Sandbox Solution
昨天在写SharePoint EventReceiver的时候遇到一个问题,创建了一个local farm SharePoint solution,添加了一个ItemAdded(SPItemEventProperties properties)事件,更新field name为Workflow的value。
1 2 3 4 5 6 7 8 9 10 11 12 13 | public override void ItemAdded(SPItemEventProperties properties) { base .ItemAdded(properties); if (properties.AfterProperties[ "Workflow" ] != null ) { string value = properties.AfterProperties[ "Workflow" ].ToString(); if (! string .IsNullOrEmpty(value)) { properties.ListItem[ "Workflow" ] = string .Empty; properties.ListItem.SystemUpdate(); } } } |
上传已包含custom field为Workflow的office file,发现properties.AfterProperties["Workflow"]这个field value一直是空。百思不得其解,向大神求教。
大神还是很热心的,下面是回复的内容:
I did a test and found that the property will be added when the file saved to the document library, here is our steps and some codes, please point out if we have some settings different from your enviroment:
1、Create 2 Document libraries(LibA and LibB),both of them contain one column field name "SyncType"
2、Create a Document in office Client, upload it to LibA ,and set the SyncType to 1
3、Now web download the file, open it in office client, click File->Show All Properties in the right bottom, we can see this property
4、Now we created a project, I used sandboxed solution, add an Event Receiver,and I used the following codes to proceed the action(get value and reset it):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | public override void ItemAdded(SPItemEventProperties properties) { base .ItemAdded(properties); try { var value = properties.AfterProperties[ "SyncType" ].ToString(); if (! string .IsNullOrEmpty(value)) { properties.ListItem[ "SyncType" ] = string .Empty; properties.ListItem.SystemUpdate(); } } catch (Exception) { throw ; } } |
5、Then I click the document I uploaded to LibA, then select open it in office client, then File->Save As, save it to the LibB,and seems everything works fine.
please let us know if we missed something.
以上是大神回复的大部分内容,瞬间被大脸,怎么回事,为什么在我这里不好用,大神确认证成功。经过昨天一下午不懈努力,终于发现了问题所在,原来是solution type的原因,sandbox solution确实可以,但是local farm solution 存在这个问题。
下面是我重现的步骤,本人也是第一次创建sandbox solution,记录了一下过程
1、创建一个sandbox solution,添加如上代码
2、Deployee solution,Site Setting->Web Designer Galleries ->Solution, check the Status is Actived
3、Attach process,if the solution endpoint is not trigger, please End process SPUCWorkerProcess.exe then retry.
果然,验证成功!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)