I am mapping one xml document to another. When it is done, I am uploading that document to a document library. Here is the code that does that:
MemoryStream ms = new MemoryStream();
XmlWriterSettings xws = new XmlWriterSettings();
xws.OmitXmlDeclaration = false;
xws.Indent = true;
using (XmlWriter xw = XmlWriter.Create(ms, xws))
{
outputDocumentInfo.Xdoc.WriteTo(xw);
}
SPFolder mylibrary = web.Folders[siteCollectionInfo.DocumentLibraryName];
// Set AllowUnsafeUpdates = true to avoid security error
web.AllowUnsafeUpdates = true;
mylibrary.Files.Add(outputDocumentInfo.FileName + ".xml", ms, true);
mylibrary.Update();
web.AllowUnsafeUpdates = false;
When the file is done uploading, it is valid and well formed xml. I can open it, submit, edit it, everything, but the status of the workflow says "Error Occurred" and the workflow will not start for that item. Under workflow settings I have made sure that " Start this workflow when a new item is created" is checked.
Anyone know what might be causing this?
Edit: When I download that same xml file and re-upload it (without making any changes) using the Upload Document button inside the document library, the workflow will start just fine.