Parts added to MainDocumentPart appear in root RRS feed

  • Question

  • Hi,


    I'm wondering if this is a bug or I'm doing anything wrong. In the code below I create a new Word doc and add the main part. So far so good. But as soon as I'm trying to add a part to the main part (highlighted line) it appears in the root instead of the word folder within the package.





    private void CreateWordDoc(string FName, string Content, string docXML)


       using (WordprocessingDocument wDoc =

       WordprocessingDocument.Create(FName, WordprocessingDocumentType.Document))


          MainDocumentPart partMain = wDoc.AddMainDocumentPart();

          XmlDocument xDocMain = new XmlDocument();



          using (StreamWriter streamMainXML =

          new StreamWriter(partMain.GetStream(FileMode.Create, FileAccess.Write)))





          Image image = Image.FromFile(<ImagePath>);

          ImagePart partImage = partMain.AddImagePart(ImagePartType.Jpeg);

          image.Save(partImage.GetStream(FileMode.Create, FileAccess.Write),



    Friday, June 22, 2007 6:45 AM

All replies

  • Actually, it doesn't matter to WORD or the ECMA spec where the part is phsycially stored; as long as the relationship has the right 'Target' attribute value. WORD will open such document with no problem. In this release, the API does not follow all WORD behavior.
    Monday, June 25, 2007 7:42 AM
  • Yes, I know that it doesn't matter to the Office apps as long as the relationships are wired correctly. But I assumed the SDK either follows MS Office or at least leaves the choice to the programmer.




    Monday, June 25, 2007 10:11 AM
  • That is an interesting  request. IMHO, I don't think it is critical to follow WORD behavior as it is not guaranteed to be fixed from version to version. So I am curious about the compelling reason of exposing the ability to programmers to specify the actual location of the parts.
    Tuesday, June 26, 2007 1:44 AM
  • There is actually no reason to follow Words behaviour. I just thought it would be consequent to lay out the folder structure the same way Word does, especially when I'm creating Word documents.
    Thursday, June 28, 2007 2:44 PM