I am trying to upload a xml document generated from an infopath 2010 form to a document library. The code is shown below
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");
}
I get the form submission failed error, but when i check the library i have my xml document uploaded succesfully. The error was :
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)
I ran the code with elevated privileges to get over this error and was successful but now the created by field shows System account for every document created, and i cannot filter the data to generate a view to show the documents created by current logged in user.
Please suggest some work arounds to get over this issue. Thanks in advance!