Nutrient

Home

SDK

Software Development Kits

Low-Code

IT Document Solutions

Workflow

Workflow Automation Platform

DWS API

Document Web Services

T
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Company

About

Team

Careers

Contact

Security

Partners

Legal

Resources

Blog

Events

Try for free

Contact Sales
Contact sales
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

products

Web

Web

Document Authoring

AI Assistant

Salesforce

Mobile

iOS

Android

visionOS

Flutter

React Native

MAUI

Server

Document Engine

Document Converter Services

.NET

Java

Node.js

AIDocument Processing

All products

solutions

USECASES

Viewing

Editing

OCR and Data Extraction

Signing

Forms

Scanning & Barcodes

Markup

Generation

Document Conversion

Redaction

Intelligent Doc. Processing

Collaboration

Authoring

Security

INdustries

Aviation

Construction

Education

Financial Services

Government

Healthcare

Legal

Life Sciences

All Solutions

Docs

Guides overview

Web

AIAssistant

Document Engine

iOS

Android

visionOS

Java

Node.js

.NET

Document Converter Services

Downloads

Demo

Support

Log in

Resources

Blog

Events

Pricing

Try for free

Free Trial

Company

About

Security

Partners

Legal

Contact Sales
Contact Sales
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

products

Products overview

Document Converter

Document Editor

Document Searchability

Document Automation Server

Integrations

SharePoint

Power Automate

Nintex

OneDrive

Teams

Window Servers

solutions

USECASES

Conversion

Editing

OCR Data Extraction

Tagging

Security Compliance

Workflow Automation

Solutions For

Overview

Legal

Public Sector

Finance

All Solutions

resources

Help center

Document Converter

Document Editor

Document Searchability

Document Automation Server

learn

Blog

Customer stories

Events

Support

Log in

Pricing

Try for free

Company

About

Security

Partners

Legal

Contact Sales
Contact Sales
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Product

Product overview

Process Builder

Form Designer

Document Viewer

Office Templating

Customization

Reporting

solutions

Industries

Healthcare

Financial

Manufacturing

Pharma

Education

Construction

Nonprofit

Local Government

Food and Beverage

Departments

ITServices

Finance

Compliance

Human Resources

Sales

Marketing

Services

Overview

Capex-accelerator

Process Consulting

Workflow Prototype

All Solutions

resources

Help center

guides

Admin guides

End user guides

Workflow templates

Form templates

Training

learn

Blog

Customer stories

Events

Support

Pricing

Support

Company

About

Security

Partners

Legal

Try for Free
Contact Sales
Try for Free
Contact Sales
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Services

Generation

Editing

Conversion

Watermarking

OCR

Table Extraction

Pricing

Docs

Log in

Try for Free
Try for Free

Free trial

Blog post

Embed .NET code in SharePoint workflows easily

Clavin Fernandes Clavin Fernandes

Table of contents

    Illustration: User guide to embedding .NET in workflows

    In part 2 of our series of User Guide related blog postings for the Muhimbi Workflow Power Pack for SharePoint we provide a number of examples of how to embed c# or vb code directly into a SharePoint Designer Workflow Condition.

    A quick introduction In case you are not familiar with the product: The Muhimbi Workflow Power Pack for SharePoint allows custom C# or VB.NET code to be embedded in SharePoint Designer Workflows without the need to resort to complex Visual Studio based workflows, the development of bespoke Workflow Activities or long development cycles.

    The following Blog postings are part of this User Guide series:

    1. Language Features: Discusses the script like syntax, the generic workflow action and condition, passing parameters, returning values from a workflow and using the MyWorkflow property.

    2. Embedding .net code in a Workflow Condition (this article): Provides a number of examples of how to use the Evaluate Custom Code condition to carry out basic as well as complex conditional tasks.

    3. Embedding .net code in a Workflow Action: Contains a number of examples of how to use the Execute Custom Code  to basically carry out any action you can think of in a SharePoint Designer Workflow.

    4. Creating Custom Methods: Shows how to create your own methods in your scripts in order to keep the code organised and easy to maintain.

    SharePoint ships with a number of Workflow Conditions to carry out basic comparisons inside your SharePoint Designer workflows. However, these Conditions are limited in scope and mainly facilitate simple comparisons of workflow variables.

    This post describes how to use the Muhimbi Workflow Power Pack to write your own conditional logic in c# and embed it directly into your SharePoint Designer workflow.

    Simple Example - File name validation

    The following example shows how to check if a document’s file name contains a reference to a highly confidential project (Project Flames). If it does then the document will be renamed automatically.

    To create this workflow, carry out the following steps:

    1. Make sure you have access to a Document Library in a site collection and the appropriate privileges to design a workflow on that site collection.

    2. Create a new workflow using SharePoint Designer.

    3. On the Workflow definition screen associate the workflow with your Document Library, tick the two “automatically start” check boxes and proceed to the next screen.

    4. Click the Conditions button and insert the Evaluate Custom Code condition.

    5. Insert the following C# based code by clicking code and then the ellipsis (…) button.

      if (MyWorkflow.Item.Name.IndexOf("Flames", StringComparison.CurrentCultureIgnoreCase) >= 0)
      {
          MyWorkflow.ReturnValue = true;
      }
      else
      {
          MyWorkflow.ReturnValue = false;
      }
    6. Add the Execute Custom Code Action and insert the following code by clicking this code and pasting the following.

      MyWorkflow.Item["Name"] = MyWorkflow.Item.Name.Replace("Flames", "XXXXX");
      MyWorkflow.Item.Update();
    7. Close the workflow designer. This will automatically check the syntax of the code embedded in the Custom Action.

    CheckFileName

    The workflow is now ready to be executed. Upload a file named “ Project Flames Hostile Takeover.docx” and watch it being renamed automatically.

    In this simple example we could have merged the conditional code into the Action. However that would not work with more complex workflows where the Action does not necessarily contain our own custom code.

    Complex example - Check field in InfoPath form

    As we have access to the full power of the .net framework, there are very few limitations to how complex the conditional code can be. In the following example we will check the value of a field stored deeply in an XML Document generated by InfoPath. To be more specific, if any of the items in the Expense claim form were filed for a day in the weekend then we will send an email to John the Expenses Manager.

    Naturally this conditional logic could have been added inside the validation of the InfoPath form itself. However, that would require access to Tom the InfoPath Expert and Tom is very busy and going on holiday tomorrow. In other words, we will need to be creative.

    To create this workflow, carry out the following steps:

    1. We need to be able to access functionality in the System.XML assembly. Add this reference to the relevant Web Application using the Workflow Power Pack Central Administration screens as described in the Administration guide.

    2. Make sure you have the appropriate privileges to create Form Libraries and design workflows on a site collection.

    3. Open InfoPath, select Customize a Sample followed by Sample - Expense Report.

    4. Select Publish from the File menu, save the form anywhere on your local system and complete the wizard to publish it to a new Document Library named Expense Forms in your site collection. There is no need to expose any columns to SharePoint.

    5. In the Expense Forms Document Library fill out the form, enter one expense in a weekend and make sure you save it to the Document Library. Don’t submit it as that will go via email.

    6. Create a new workflow using SharePoint Designer.

    7. On the Workflow definition screen associate the workflow with your new Expense Forms Document Library, tick the two “automatically start” check boxes and proceed to the next screen.

    8. Click the Conditions button and insert the Evaluate Custom Code condition.

    9. Insert the following C# based code by clicking code and then the ellipsis (…) button.

      using System.Xml;
      using System.IO;
      // ** Innocent until proven guilty
      MyWorkflow.ReturnValue = false;
      XmlDocument doc = new XmlDocument();
      // ** Load the XML Form data out of the current item
      using(Stream s = MyWorkflow.Item.File.OpenBinaryStream())
      {
          doc.Load(s);
          // ** Make sure we can query the namespaces properly.
          XmlNamespaceManager xnsm = new XmlNamespaceManager(doc.NameTable);
          xnsm.AddNamespace("my",
              "https://schemas.microsoft.com/office/infopath/2003/myXSD/2005-10-21T21:12:27");
          // ** Select all date nodes and iterate through them
          XmlNodeList list = doc.SelectNodes("//my:date", xnsm);
          foreach (XmlNode node in list)
          {
              // ** Convert the date string to a real date
              DateTime expenseDate = DateTime.ParseExact(node.InnerText, "yyyy-MM-dd", null);
              if (expenseDate.DayOfWeek == DayOfWeek.Saturday ||
                  expenseDate.DayOfWeek == DayOfWeek.Sunday)
              {
                  MyWorkflow.ReturnValue = true;
                  break;
              }
          }
      }
    10. Click the Actions button and select the Send an Email activity and fill in the blanks to make it send an email to the relevant manager.

    11. Close the Workflow Designer and re-save the previously saved Expense Form to trigger the workflow.

    CheckExpense

    .

    Author
    Clavin Fernandes
    Clavin Fernandes Developer Relations and Support Services

    Clavin is a Microsoft Business Applications MVP who supports 1,000+ high-level enterprise customers with challenges related to PDF conversion in combination with SharePoint on-premises Office 365, Azure, Nintex, K2, and Power Platform mostly no-code solutions.

    Explore related topics

    Low-Code
    Free trial Ready to get started?
    Free trial

    Related articles

    Explore more
    LOW-CODELow-CodeAIOCRDigital Transformation

    Digital transformation is failing without intelligent document automation

    SDKINSIGHTSLow-CodeWorkflow AutomationDocument Converter for SharePointDocument SearchabilityDocument Automation ServerDocument Editor

    The rise of no-code and low-code: Are enterprises ready for the next document revolution?

    SDKTUTORIALSSDKLow-CodeDocument ManagementIndexingSearchingArchivingSharePointPower Automate

    How to manage large document libraries: Indexing, searching, and archiving

    Company
    About
    Security
    Team
    Careers
    We're hiring
    Partners
    Legal
    Products
    SDK
    Low-Code
    Workflow
    DWS API
    resources
    Blog
    Events
    Customer Stories
    Tutorials
    News
    connect
    Contact
    LinkedIn
    YouTube
    Discord
    X
    Facebook
    Popular
    Java PDF Library
    Tag Text
    PDF SDK Viewer
    Tag Text
    React Native PDF SDK
    Tag Text
    PDF SDK
    Tag Text
    iOS PDF Viewer
    Tag Text
    PDF Viewer SDK/Library
    Tag Text
    PDF Generation
    Tag Text
    SDK
    Web
    Tag Text
    Mobile/VR
    Tag Text
    Server
    Tag Text
    Use Cases
    Tag Text
    Industries
    Tag Text
    Resources
    Blog
    Tag Text
    Events
    Customer Stories
    Tag Text
    Tutorials
    Tag Text
    Features List
    Tag Text
    Compare
    Tag Text
    community
    Free Trial
    Tag Text
    Documentation
    Tag Text
    Nutrient Portal
    Tag Text
    Contact Support
    Tag Text
    Company
    About
    Tag Text
    Security
    Tag Text
    Careers
    Tag Text
    Legal
    Tag Text
    Pricing
    Tag Text
    Partners
    Tag Text
    connect
    Contact
    Tag Text
    LinkedIn
    Tag Text
    YouTube
    Tag Text
    Discord
    Tag Text
    X
    Tag Text
    Facebook
    Tag Text
    low-code
    Document Converter
    Tag Text
    Document Editor
    Tag Text
    Document Automation Server
    Tag Text
    Document Searchability
    Tag Text
    Use Cases
    Tag Text
    Industries
    Tag Text
    Resources
    Blog
    Tag Text
    Events
    Customer Stories
    Tag Text
    Support
    Help Center
    Tag Text
    Contact Support
    Tag Text
    Log In
    Tag Text
    Company
    About
    Tag Text
    Careers
    Tag Text
    Security
    Tag Text
    Legal
    Tag Text
    Pricing
    Tag Text
    Partners
    Tag Text
    connect
    Contact
    Tag Text
    LinkedIn
    Tag Text
    YouTube
    Tag Text
    Discord
    Tag Text
    X
    Tag Text
    Facebook
    Tag Text
    Popular
    Approvals matrix
    Tag Text
    BPMS
    Tag Text
    Budgeting process
    Tag Text
    CapEx approval
    Tag Text
    CapEx automation
    Tag Text
    Document approval
    Tag Text
    Task automation
    Tag Text
    workflow
    Overview
    Tag Text
    Services
    Tag Text
    Industries
    Tag Text
    Departments
    Tag Text
    Resources
    Blog
    Tag Text
    Events
    Customer Stories
    Tag Text
    Support
    Help Center
    Tag Text
    FAQ
    Tag Text
    Troubleshooting
    Tag Text
    Contact Support
    Tag Text
    Company
    About
    Tag Text
    Careers
    Tag Text
    Security
    Tag Text
    Legal
    Tag Text
    Pricing
    Tag Text
    Partners
    Tag Text
    connect
    Contact
    Tag Text
    LinkedIn
    Tag Text
    YouTube
    Tag Text
    Discord
    Tag Text
    X
    Tag Text
    Facebook
    Tag Text
    DWS api
    PDF Generator
    Tag Text
    Editor
    Tag Text
    Converter API
    Tag Text
    Watermark
    Tag Text
    OCR
    Tag Text
    Table Extraction
    Tag Text
    Resources
    Log in
    Tag Text
    Help Center
    Tag Text
    Support
    Tag Text
    Blog
    Tag Text
    Company
    About
    Tag Text
    Careers
    Tag Text
    Security
    Tag Text
    Pricing
    Tag Text
    Legal
    Privacy
    Tag Text
    Terms
    Tag Text
    connect
    Contact
    Tag Text
    X
    Tag Text
    YouTube
    Tag Text
    Discord
    Tag Text
    LinkedIn
    Tag Text
    Facebook
    Tag Text

    Copyright 2025 Nutrient. All rights reserved.

    Thank you for subscribing to our newsletter!

    We’re thrilled to have you join our community. You’re now one step closer to receiving the latest updates, exclusive content, and special offers directly in your inbox.

    This builtin is not currently supported: DOM

    PSPDFKit is now Nutrient. We've consolidated our group of trusted companies into one unified brand: Nutrient. Learn more

    This builtin is not currently supported: DOM

    PSPDFKit is now Nutrient. We've consolidated our group of trusted companies into one unified brand: Nutrient. Learn more

    This builtin is not currently supported: DOM

    New Feature Release. Tap into revolutionary AI technology to instantly complete tasks, analyze text, and redact key information across your documents. Learn More or View Showcase

    This builtin is not currently supported: DOM

    Aquaforest and Muhimbi are now Nutrient. We've consolidated our group of trusted companies into one unified brand: Nutrient. Learn more

    This builtin is not currently supported: DOM

    Integrify is now Nutrient. We've consolidated our group of trusted companies into one unified brand: Nutrient. Learn more

    This builtin is not currently supported: DOM

    Join us on April 15th. Join industry leaders, product experts, and fellow professionals at our exclusive user conference. Register for conference