Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin
Introducedin
4.5
4.5
Description

Excerpt

Writes a Document to a file and saves it to a SharePoint List Item.

Signature
C#
C#
public static void Save(this WordApplication wordApplication, Document document, Microsoft.SharePoint.SPListItem listItem, string fileName)
Signature
vb.net
vb.net
Public Shared Sub Save(ByVal wordApplication As WordApplication, ByVal document As Document, ByVal docLib As Microsoft.SharePoint.SPListItem, ByVal fileName As String)
Parameters
Param
wordApplication
wordApplication

The current WordApplication object from which Save is being called

Param
document
document

The Document to save.

Param
listItem
listItem

The SharePoint List Item to which the file will be saved

Param
fileName
fileName

Filename of the Document

Exceptions
Exception
System.Exception
System.Exception

Thrown if there is an error saving the file.

Remarks

The WordApplication.Preserve property is used to specify the way WordWriter will save the document. When the preserve property is set to true, WordWriter attempts to preserve all formatting and features that it doesn't directly support. This includes Fields, Footnotes, Hyperlinks, Comments, and Anchored Images. When the preserve property is false, only those features directly supported by WordWriter will be preserved. This includes all Tables, Lists, Headers and Footers.

Note

This is an extension method for the WordApplication object to be used for saving documents to a SharePoint List Item from within SharePoint. To use this method, you must add a reference to SoftArtisans.OfficeWriter.WordWriter.SharePointIntegration.dll

Example
Code Block
csharp
csharp
titleC#
//--- Retrieve current AllowUnsafeUpdates value
bool currentAllowUnsafeUpdates = list.ParentWeb.AllowUnsafeUpdates;

//--- You must allow unsafe updates in order for the file to be saved in the
//--- List from a web application
list.ParentWeb.AllowUnsafeUpdates = true;
wa.Save(doc, listItem, "populated.doc");

//--- Update the list
listItem.Update();

//--- Return the AllowUnsafeUpdates value to its original state
list.ParentWeb.AllowUnsafeUpdates = currentAllowUnsafeUpdates;
        
Code Block
vb.net
vb.net
titlevb.net
'--- Retrieve current AllowUnsafeUpdates value
Dim currentAllowUnsafeUpdates As Boolean = list.ParentWeb.AllowUnsafeUpdates

'--- You must allow unsafe updates in order for the file to be saved in the
'--- List from a web application
list.ParentWeb.AllowUnsafeUpdates = True
wa.Save(doc, listItem, "populated.doc")

'--- Update the list
listItem.Update()

'--- Return the AllowUnsafeUpdates value to its original state
list.ParentWeb.AllowUnsafeUpdates = currentAllowUnsafeUpdates