不确定,因为我不使用 Sharepoint,但是查看文档,您需要在尝试在其中设置值之前创建字段“PercentComplete”。
SPListItem itemUpdate = web.Lists["ListName"].Items[itemId];
itemUpdate.Fields.CreateNewField("PercentComplete", "PercentComplete");
itemUpdate["PercentComplete"] = .45;
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splistitem.fields.aspx
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfieldcollection_methods.aspx
希望SharePoint方面的专家能给你一个更好的答案......
附带说明:没有办法忽略异常。异常是“异常”事件。您无法预料的事情,而不是您可以通过适当的编码阻止发生的事情。访问不存在的项目是一种不好的做法,您可以轻松避免它。如果您希望可以设置一个全局异常处理程序来处理所有未捕获的异常,请将这样的代码添加到您的 main 方法
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
AppDomain.CurrentDomain.UnhandledException +=
new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
然后准备以下方法
private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
{
string msg = "Not recognized error:" + e.Exception.Message;
if (e.Exception.InnerException != null)
{
msg = msg + "\r\nPrevious error:" + e.Exception.InnerException.Message;
}
msg = msg + "\r\nStackTrace:" + e.Exception.StackTrace;
msg = msg + "\r\nDo you wish to continue with the application?";
DialogResult dr = AskAQuestion(msg);
.. add logging here ...
if (dr == DialogResult.No) Application.Exit();
}
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Exception ex = e.ExceptionObject as Exception;
if (ex != null)
{
string msg = "Not recognized error:" + e.Exception.Message;
if (e.Exception.InnerException != null)
{
msg = msg + "\r\nPrevious error:" + e.Exception.InnerException.Message;
}
msg = msg + "\r\nStackTrace:" + e.Exception.StackTrace;
.. add logging here ...
}
}