Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
1  
Try to check sharepoint log file (14/LOGS folder). I think that it should has detailed information about the exeption. –  Alexander Nov 10 '11 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. –  Yuri Leontyev Nov 10 '11 at 8:15
add comment

1 Answer 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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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