Follow

C# Server Side Scripting Help

Applies To: Information Worker for SharePoint 2013/2016/2019

 

One of the easiest and most powerful ways to customize PDF files is by using C# Script. Based on C# language, script in PDF Share Forms software implements objects, methods, and properties that enable you to manipulate PDF files, produce database-driven actions, customize SharePoint entities, and much more. You can tie C# code to a specific PDF server-side event (for example 'On Form Loading'.

C# is particularly useful for SharePoint integration. C# enables automated forms handling, SharePoint communication, and user-interface capabilities.

C# code is being executed on server while processing the form. Scripting context gives access to current SharePoint context and form data, which allows preloading data, modifying values, and integrating with external data.

Publishing form with server side scripts requires user to be a member of “Script Deployment Group” permission group (Set up in Central Administration → PDF Share Forms → Permissions).

Following assemblies are always available in the scripting execution context:

  • System.dll
  • System.Core.dll
  • System.Xml.dll
  • System.Xml.Linq.dll

Farm administrator can setup additional assemblies and namespaces to be available in server-side scripting. To add additional approved assemblies, go to Central Administration → PDF Share Forms → Scripting Assemblies.

The main goal is to give the ability to manipulate form fields in connection with some other data sources, such as SharePoint object model or BCS.

General Scripting

Following contextual variables are available:

ScriptingData data 
ScriptingContext context 

Examples:

Set field named "CurrentDateField" value to current time:

data.ResolveNode("CurrentDateField").Value = DateTime.Now.ToString();

Set field "CurrentUser" value to current SharePoint user name:

data.ResolveNode("CurrentUser").Value = context.SystemData.CurrentUser.Name;

Set default value if form is new:

if (context.SystemData.IsFormNew) {
 data.ResolveNode("TextField1").Value = "some default value";
}

Classes

ScriptingData

Gives access to form data. Data is represented as xml, root element is always named "fields" (not visible in designer). Elements under root are visible in "Data fields" pane in designer. XML node name attribute is equal to PDF form field name:

<fields>
<field name="TextField1">Field value</field>
<field name="TextField2">Other value</field>
</fields>

Properties

XElement Data
Gets Root element of data structure

Methods

DataField ResolveNode(string nodeName)

Searches for data field from form data structure. nodeName can be field name, field path or SOM path expression.

  • Field name is name visible in designer, e.g. "TextField1"
  • Field path is field full path, including parent groups, e.g. "Root.Subform1.Subform2.TextField1". Here TextField1 is contained in Subform2, which is contained in Subform1, which is contained in Root. Data root element is always called "Root"

ScriptingContext

Provides access to SharePoint objects used in context of current PDF action request such as document library, content type and current item.

Properties

FormSystemData SystemData
Gets access to SystemData object.
SPContentType ContentType
Gets Content type of current PDF document. Null if deployed to external list.
SPList List
Gets List where current PDF is/will be submitted.
SPFolder Folder
Gets Folder where current PDF is/will be submitted.
SPFile File
Gets File that corresponds to current PDF. Null if new document or if deployed to external list.
SPListItem Item 
Gets List item that corresponds to current PDF. Null if new document.

Methods

void SetNewFilename(string newFileName)

Sets form file name if form is new. Enables you to customize file naming for new form instances.

DataField

Represents data fields in PDF form.

Properties

XElement Element
Gets or sets first xml node, that corresponds to the form field
string Name
Gets data field name
string Value
Gets or sets data field value.
For repeatable fields use xml elements directly.

FormSystemData

Represents system fields and properties of PDF form

Properties

SiteProxyBase Site
Gets access to proxy object associated with current SharePoint SPSite object.
WebProxyBase Web
Gets access to proxy object associated with current SharePoint SPWeb object.
UserProxyBase CurrentUser
Gets access to proxy object associated with current SharePoint SPWeb.CurrentUser object.
ContentTypeProxyBase ContentType
Gets access to proxy object assocaited with current SharePoint ContentType object.
ListProxyBase List
Gets access to proxy object assocaited with current SharePoint SPList object.
FileProxyBase File
Gets access to proxy object assocaited with current SharePoint SPFile object.
ListItemProxyBase Item
Gets access to proxy object assocaited with current SharePoint SPListItem object.
FolderProxyBase Folder
Gets access to proxy object assocaited with current SharePoint SPFolder object.
Dictionary<string, string> RequestQueryParams
Access to Query parameters in Web Request. This object is null for OnSync or Email operations

SiteProxyBase

A proxy object that is similar to SharePoint SPSite object. It has a minimal set of properties.

Properties

Guid Id
Represents a Id property of SPSite object.
string Url
Represents a Url property of SPSite object.

WebProxyBase

A proxy object that is similar to SharePoint SPWeb object. It has a minimal set of properties.

Properties

Guid Id
Represents a Id property of SPWeb object.
string Url
Represents a Url property of SPWeb object.
SiteProxyBase ParentSite
Represents a Site property of SPWeb object.

UserProxyBase

A proxy object that is similar to SharePoint SPUser object. It has a minimal set of properties.

Properties

int ID
Represents a ID property of SPUser object.
string Name
Represents a Name property of SPUser object.
string Login
Represents a Login property of SPUser object.
WebProxyBase ParentWeb
Represents a Web property of SPUser object.

 

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.
Powered by Zendesk