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.1.0.1379
4.1.0.1379
Description

Excerpt

Saves the generated Word file to a SharePoint List Item.

Signature
C#
C#
public static void Save(this WordTemplate template, Microsoft.SharePoint.ListItem listItem, string fileName)
Signature
vb.net
vb.net
Public Shared Sub Save(ByVal template As WordTemplate, ByVal listItem As Microsoft.SharePoint.ListItem, ByVal fileName As String)
Parameters
Param
template
template

The current WordTemplate object that is being saved to file

Param
listItem
listItem

SharePoint List Item to which the file is being saved

Param
fileName
fileName

Name of the file to be saved

Exceptions
Exception
ArgumentNullException
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.

Note

This is an extension method for the WordTemplate 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;
wt.Save(listItem, "populated.docx");

//--- 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
wt.Save(listItem, "populated.docx")

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

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