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

Saves the generated Word file to a SharePoint Document Library.

Signature
C#C#
}
{description}
{excerpt}Saves the generated Word file to a SharePoint Document Library.
{excerpt}
{signature:C#}
public static void Save(this WordTemplate template, Microsoft.SharePoint.DocumentLibrary docLib, string fileName, bool overwrite)
Signature
{signature}
{signature:vb.net
vb.net
}
Public Shared Sub Save(ByVal template As WordTemplate, ByVal docLib As Microsoft.SharePoint.DocumentLibrary, ByVal fileName As String, ByVal overwrite As Boolean)
Parameters

...

The current WordTemplate object that is being saved to file

...

SharePoint document library to which the file is being saved

...

Name of the file to be saved

...

If set to true, will overwrite any files in the Document Library by that name

Exceptions
This is an extension method for the WordTemplate 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:template}The current WordTemplate object that is being saved to file
{param}
{param:docLib}SharePoint document library to which the file is being saved{param}
{param:fileName}Name of the file to be saved{param}
{param:overwrite}If set to true, will overwrite any files in the Document Library by that name{param}
{exceptions}
{exception:ArgumentNullException}{{Save}} will throw this exception if {{null}} \(C\#\) or {{Nothing}} \(VB.NET\) is passed to the method.
{exception}
{remarks}You can call [Save|WordTemplate.Save] more than once for a single instance of [WordTemplate]. This allows you to save more than one copy of a generated file, and/or both save the file on the server and stream it to the client.
{note}This is an extension method for the WordTemplate 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;
wt.Save(documentLibrary, "populated.docx", 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
wt.Save(documentLibrary, "populated.docx", True)

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

'--- Return the AllowUnsafeUpdates value to its original state
documentLibrary.ParentWeb.AllowUnsafeUpdates = currentAllowUnsafeUpdates
{code}
{example}
Exception
ArgumentNullExceptionArgumentNullException

Save will throw this exception if null (C#) or Nothing (VB.NET) is passed to the method.

Remarks

You can call Save more than once for a single instance of WordTemplate. This allows you to save more than one copy of a generated file, and/or both save the file on the server and stream it to the client.

Note
Example
Code Block
csharpcsharp
titleC#
Code Block
vb.nettitle