Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

...

Wiki Markup
{introducedin:4.1.0.1379

...

Description

Excerpt

Writes a Document to a file and saves it to a SharePoint Document Library.

Signature
C#C#
}
{description}
{excerpt}Writes a [Document|Document] to a file and saves it to a SharePoint Document Library.{excerpt}
{signature:C#}
public static void Save(this WordApplication wordApplication, Document document, Microsoft.SharePoint.SPDocumentLibrary docLib, string fileName, bool overwrite)
Signature
{signature}{signature:vb.net
vb.net
}
Public Shared Sub Save(ByVal wordApplication As WordApplication, ByVal document As Document, ByVal docLib As Microsoft.SharePoint.SPDocumentLibrary, ByVal fileName As String, ByVal overwrite As Boolean)
Parameters

...

The current WordApplication object from which Save is being called

...

The Document to save.

...

The SharePoint Document Library to which the file will be saved

...

Filename of the Document

...

If true, will overwrite an existing file of the same name in the Document Library

Exceptions
This is an extension method for the WordApplication object to be used for saving documents to a SharePoint Document Library from within SharePoint. To use this method, you must add a reference to
{signature}
{parameters}
{param:wordApplication}The current WordApplication object from which Save is being called{param}
{param:document}The {{Document}} to save.{param}
{param:docLib}The SharePoint Document Library to which the file will be saved{param}
{param:fileName}Filename of the {{Document}}{param}
{param:overwrite}If true, will overwrite an existing file of the same name in the Document Library{param}
{exceptions}
{exception:System.Exception}Thrown if there is an error saving the file.{exception}
{remarks}The [WordApplication.Preserve|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 Document Library from within SharePoint.  To use this method, you must add a reference to SoftArtisans.OfficeWriter.WordWriter.SharePointIntegration.dll
{note}
{remarks}
{example}
{code:csharp|title=C#}
//--- Retrieve current AllowUnsafeUpdates value
bool currentAllowUnsafeUpdates = documentLibrary.ParentWeb.AllowUnsafeUpdates;

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

//--- Update the document library
documentLibrary.Update();

//--- Return the AllowUnsafeUpdates value to its original state
documentLibrary.ParentWeb.AllowUnsafeUpdates = currentAllowUnsafeUpdates;
{code}
{code:vb.net
|title=vb.net
}
'--- Retrieve current AllowUnsafeUpdates value
Dim currentAllowUnsafeUpdates As Boolean = documentLibrary.ParentWeb.AllowUnsafeUpdates

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

'--- Update the document library
documentLibrary.Update()

'--- Return the AllowUnsafeUpdates value to its original state
documentLibrary.ParentWeb.AllowUnsafeUpdates = currentAllowUnsafeUpdates
{code}
{example}
Exception
System.ExceptionSystem.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
Example
Code Block
csharpcsharp
titleC#
Code Block
vb.nettitle