Online Training On SharePoint
                      

Friday, 9 January 2009

Getting SharePoint Designer WorkFlow Files

Recently we had a requirement where we need to process the files created by SharePoint Designer for the SharePoint Designer work flows. Any SharePoint Designer Workflow creates 4 files from which we need to read the data for .xoml and .xoml.rule files. These files stores the data for all the conditions and actions while creating the SharePoint Designer Workflow. Since these files are stored Content DB we can not read them and process them. Also SharePoint Object Model does not provide any method of doing so. So the only option left to store them in the File System and process these files by reading line by line.

With the following code these files can be saved to the local file system:

SPSite site = new SPSite({siteurl}); // Pass the siteurl in this.
SPWeb web = site.OpenWeb();
//These files are stored in the Workflow folder.
SPFolder folder = web.Folders["WorkFlows"];
//Pass the WorkFlow name
foreach (SPFile file in folder.SubFolders[{WorkFlowName}].Files)
{
byte[] bytes = file.OpenBinary();
FileStream fs = new FileStream({FilePath} + @"\" + file.Name, FileMode.Create);
fs.Write(bytes, 0, bytes.Length);
fs.Close();
fs.Dispose();
}

Attempt a Question on SharePoint Designer


Post a Comment
Related Posts with Thumbnails