Sharepoint 2010 Forum

 
Home » Forum » Sharepoint 2010       Ask a questionRSS Feeds

Office 365 - Generate Word Documents

  Date: Oct 14, 2011      Category: Sharepoint 2010      Views: 196
 

I have a solution that works great for generating Word documents from
SharePoint 2010 list data. We are now testing Office 365 as a possible
platform for the future. From testing so far, it doesn't seem possible to
generate documents from list data within Office 365 itself.

Anyone have experience with developing solutions for Office 365?

Tagged:          

 

3 Answers Found

 
Answer #1       Answered On: Oct 14, 2011       

You can use Quick Parts to generate Word documents from list item data:

blogs.technet.com/.../automatically-creat
e-word-documents-which-include-list-fields.aspx

 
Answer #2       Answered On: Oct 14, 2011       

How are you generating them, and what piece is falling short in 365?

 
Answer #3       Answered On: Oct 14, 2011       

The issue is when creating the template file, I get an error that this
is not compatible with sandboxed solutions.

try
{
Stream docStream = new MemoryStream();
SPContentType contentType =
volunteersDocLib.ContentTypeOrder[int.Parse(lstContentTypes.SelectedValue)];

SPFile templateFile =
contentType.ResourceFolder.Files[contentType.DocumentTemplate];
Stream templateStream = templateFile.OpenBinaryStream();
BinaryReader reader = new BinaryReader(templateStream);
BinaryWriter writer = new BinaryWriter(docStream);
writer.Write(reader.ReadBytes((int)templateStream.Length));
writer.Flush();
reader.Close();
templateStream.Dispose();

//insert custom xml part into the document stream
SPListItem volunteerItem = null;
volunteerItem =
webObj.Lists[this.listId].GetItemById(this.itemId);
//open .docx file in memory stream as package file
docStream.Position = 0;

//Begin edits here for Open XML SDK
WordprocessingDocument wordDoc =
WordprocessingDocument.Open(docStream, true);
MainDocumentPart mainPart = wordDoc.MainDocumentPart;

//retrieve package part with XML data
XmlDocument xDoc = null;
CustomXmlPart customPart = null;

foreach (CustomXmlPart cp in mainPart.CustomXmlParts)
{
xDoc = new XmlDocument();
xDoc.Load(cp.GetStream());
if (xDoc.DocumentElement.NamespaceURI ==
"http://www.sample.com/2011/schemas/volunteer/")
{
customPart = cp;
break;
}
}

//serialize the contact item into this customXml part
XmlNode rootNode = xDoc.DocumentElement;
rootNode.RemoveAll();
foreach (SPField field in contactItem.Fields)
{
XmlNode fieldNode = xDoc.CreateElement("sc",
XmlConvert.EncodeName(field.Title),
"http://www.sample.com/2011/schemas/volunteer/");
if (contactItem[field.Id] != null)
{
XmlNode fieldVal =
xDoc.CreateTextNode(contactItem[field.Id].ToString());
fieldNode.AppendChild(fieldVal);
}
rootNode.AppendChild(fieldNode);
}

xDoc.Save(customPart.GetStream(FileMode.Create,
FileAccess.Write));
//deliver file to library
volunteersDocLib.Files.Add(txtFileName.Text, docStream);
lblMessage.Visible = true;

}
catch (Exception ex)
{
Response.Write(ex.ToString());
}

 
Didn't find what you were looking for? Find more on Office 365 - Generate Word Documents Or get search suggestion and latest updates.


Your Answer
  • Answer should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].