2

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.

2
  • 1
    Try to check sharepoint log file (14/LOGS folder). I think that it should has detailed information about the exeption.
    – Alexander
    Commented Nov 10, 2011 at 8:10
  • Or try to debug the workflow using VS to get detailed error, cause current description it almost impossible to understand the reason of failure. Commented Nov 10, 2011 at 8:15

1 Answer 1

1

do not use web.AllowUnsafeUpdates = false; inside the workflow code instead use

using (spWeb web= workflowProperties.web)
{
web.AllowUnsafeUpdates = true;

}

this will resolve yor issue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.