Quantcast
Viewing all articles
Browse latest Browse all 25064

SharePoint 2013 Workflow Context in Custom Code Activity

I'm writing a custom code activity for workflows on the SharePoint 2013 platform and was hoping someone could show me how to access the workflow context in C# to get the current site URL. I know in SP 2010 custom activities you could pass in the __context parameter and then access that in your inherited Activity class, but is this possible in SP 2013? I can see that the execute method has an argument of the CodeActivityContext class but I don't see how to get workflow context specific properties from that variable.

See example code below and comment about getting the current site URL

// Example Code
public sealed class TestActivity : CodeActivity<System.Guid>
    {
        // Define Input Arguments
        public InArgument<System.Guid> TestListId { get; set; }
        public InArgument<System.Guid> TestListItemId { get; set; }

        // Define Output Arguments
        public OutArgument<System.Guid> ListItemId { get; set; }

        // Overidden Excute Method of CodeActivity Class
        protected override System.Guid Execute(CodeActivityContext context)
        {
            using (SPSite Site = new SPSite("http:/host/site")) //This is where I need workflow context to get current site URL
            {
                using (SPWeb Web = Site.OpenWeb())
                {
                    SPDocumentLibrary TestLibrary = Web.Lists[context.GetValue(this.TestListId)] as SPDocumentLibrary;
                    SPFile TestDocument = Web.GetFile(context.GetValue(this.TestListItemId));
                    context.SetValue(this.ListItemId, TestDocument.UniqueId);
                }
            }
            return context.GetValue(this.ListItemId);
        }
    }
Any help is much appreciated!

Viewing all articles
Browse latest Browse all 25064

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>