Introduced in build 4.1.0.1379
Description
Saves the generated Word file to a SharePoint Document Library.
C#
public static void Save(this WordTemplate template, Microsoft.SharePoint.DocumentLibrary docLib, string fileName, bool overwrite)
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
template
The current WordTemplate object that is being saved to filedocLib
SharePoint document library to which the file is being savedfileName
Name of the file to be savedoverwrite
If set to true, will overwrite any files in the Document Library by that nameExceptions
ArgumentNullException
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.
Examples
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;
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
