SharePoint Designer Workflow Issues

SharePoint Designer

SharePoint Designer is one of the best tools you can have when working with SharePoint. It allows you to do pretty much anything you can in a typical SharePoint interface. For me one of the best aspect of SharePoint Designer is giving Power Users the ability to create customized workflows. This helps them automate business processes while allowing users work on normal SharePoint lists and Document Libraries. However there are also many know SharePoint Designer Workflow issues like the one below.

Workflow Issues

Unfortunately there are times that after publishing some changes, it doesn’t reflect properly. In my experience, what happened was I changed some e-mail content and updating of columns but after publishing it nothing happened.

It’s very hard to figure out most of the time why this happens. There was even a time before where I even had to delete all actions and conditions just to check what’s wrong. The worst part was when I had to recreate a workflow just to make it work!

The Solution

After searching online and asking around, I found out that this was because of the caching mechanism in SharePoint Designer. If you encounter this issue, most of the time it’s because of this reason. In order to solve the issue you need to do the following:

SharePoint 2010

 

  1. Close your SharePoint Designer
  2. Navigate to this directory %USERPROFILE%\AppData\Local\Microsoft\WebsiteCache
  3. Copy all files in this folder and save them somewhere (for backup purposes).
  4. Delete all the files in the said directory.
  5. Navigate to this directory %APPDATA%\Microsoft\Web Server Extensions\Cache
  6. Copy all the files in this folder and save them somewhere (for backup purposes).
  7. Delete all the files in the said directory.
  8. Open your SharePoint Designer and try to publish your workflow again.

SharePoint 2013

  1. Go to Files > Options > General > Application Options
  2. In the General tab, under the General header, check if the “Cache site data across SharePoint Designer sessions” is ticked. If it is, remove it.
  3. Open your SharePoint Designer and try to publish your workflow again.

This should do the trick. If you encounter this issue and have problems after following my instructions please let me know in the comments.

List Template and List Creation using List Template via PowerShell

Recently I was tasked to create multiple SharePoint lists based list templates. Initially I did them manually because it was less than 10 lists. Basically what I have are STP files and I create new lists based from those STP files. Eventually the requests became too many that I decided to do them using powershell. Below is the code block I used:

$web = Get-SPWeb <site url>
$site = Get-SPSite <site url>

//uploads the STP file from local to template gallery
$listTmplGal  = $web.GetFolder("List Template Gallery")
$listTmplFiles = $listTmplGal.Files
$tmplFile = Get-ChildItem "<full path of stp>"
$listTmplFiles.Add("_catalogs/lt/<template.stp>", $tmplFile .OpenRead(), $true)
 
//creates the list using the template uploaded
$listTemplates = $site.GetCustomListTemplates($web)
$web.Lists.Add("<name of list>", "<description of list>", $listTemplates["<template name>"])

The code block above can be turned into a function such that you can just pass the url of your site, the path of the stp file and other variables to help you automate your process. I hope this helps!

Working with Certificates in SharePoint Applications

I recently worked on a task which asked me to integrate an existing SharePoint app to one of our service providers. It’s a straight forward task where in I just need to consume a service from them and work with the output provided by that service. We were required by the service provider to give them a public key which was signed using our own private key.

I initially created a console application to perform a simple checking to test if all is well and good. It’s just like creating your first HelloWorld while consuming a service. Everything went well and I was able to call the service and get the response needed so I decided to integrate it in our application.

I thought to myself, “Wow this was really an easy task!”. Unfortunately I immediately hit a road block and kept getting an error whenever I try to read my private key. Below is the code block responsible for reading the certificate from the cert store:

       ...

        X509Certificate2 privateCert = null;
        X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
        store.Open(OpenFlags.MaxAllowed);

        var certs = store.Certificates.Find(X509FindType.FindByThumbprint, "<thumbprinthere>", true);

        if (certs.Count > 0)
        {
            privateCert = certs[0];
        }

        RSACryptoServiceProvider key = new RSACryptoServiceProvider();
        key.FromXmlString(privateCert.PrivateKey.ToXmlString(true));

        byte[] sig = key.SignData(Encoding.ASCII.GetBytes(data), CryptoConfig.MapNameToOID("SHA256"));
        string signature = Convert.ToBase64String(sig);

        ...    

I kept getting an error whenever I try to call the line which reads the private key from the certificate. I tried lots of stuff based from the different suggestions online but none seemed to work. I even went as far as posting this problem in Stackoverflow.

Apparently I just missed wrapping my entire code block above inside the SPSecurity.RunWithElevatedPrivileges. For those who are not familiar, SPSecurity.RunWithElevatedPrivileges allows you to execute a block of code under the application pool account. Since the application pool account of my SharePoint site has full control, it allowed me to read the private key from the certificate with no issues