我正在尝试将从infopath 2010表单生成的xml文档上传到文档库。代码如下所示
using (SPSite site = new SPSite(this.Context.Request.Url.AbsoluteUri))
{
sb.AppendLine("site URL : " + site.Url);
SPWeb web = site.RootWeb;
//SPWeb web = SPContext.Current.Site.RootWeb;
sb.AppendLine("Web URL : " + web.Url);
SPDocumentLibrary docLib = web.Lists["Supplier Requests Library"] as SPDocumentLibrary;
string destUrl = docLib.RootFolder.Url + "/" + countryName + "/" + supplierCategory + "/" + supplierNumber + " " + supplierName + ".xml";
sb.AppendLine("destination URL : " + destUrl);
web.AllowUnsafeUpdates = true;
SPFile destFile = docLib.RootFolder.Files.Add(destUrl.Trim(), document, true,"",false);
destFile.Update();
docLib.Update();
web.AllowUnsafeUpdates = false;
sb.AppendLine("document uploaded successfully");
}
我收到表单提交失败错误,但是当我检查库时,我已成功上传了我的xml文档。 错误是:
System.Threading.ThreadAbortException: Thread was being aborted.
at System.Threading.Thread.AbortInternal()
at System.Threading.Thread.Abort(Object stateInfo)
at System.Web.HttpResponse.End()
at Microsoft.SharePoint.Utilities.SPUtilityInternal.SendResponse(HttpContext context, Int32 code, String strBody)
at Microsoft.SharePoint.Utilities.SPUtility.HandleAccessDenied(HttpContext context)
at Microsoft.SharePoint.Utilities.SPUtility.HandleAccessDenied(Exception ex)
at Microsoft.SharePoint.Library.SPRequest.SetListProps(String bstrUrl, String bstrListName, Boolean bMigrate)
at Microsoft.SharePoint.SPList.Update(Boolean bFromMigration)
at SupplierWebService.SubmitFormData(Byte[] document)
System.Threading.ThreadAbortException: Thread was being aborted.
at SupplierWebService.SubmitFormData(Byte[] document)
at SupplierWebService.SubmitFromData(XmlDocument document)
我使用提升的权限运行代码来克服此错误并且成功但现在创建的字段显示创建的每个文档的系统帐户,并且我无法过滤数据以生成视图以显示由当前记录创建的文档在用户。
请建议一些解决此问题的方法。提前谢谢!
答案 0 :(得分:0)
这通常在您进行重定向时发生。你能检查一下是否是这种情况? Sample thread如果它提供了任何指针。
答案 1 :(得分:0)
请勿致电doclib.Update()
。您没有更改任何列表元数据,而是要添加数据。
另外,为什么要启用不安全的更新?