Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I created an custom workflow activity with the following code:

namespace Custom.SharePoint
{
    public class CustomActivity : Activity
    {
        #region Fields
        public static readonly DependencyProperty __ContextProperty =
            DependencyProperty.Register("__Context", typeof(WorkflowContext), typeof(WebServiceActivity));

        public static readonly DependencyProperty AddressProperty =
            DependencyProperty.Register("Address", typeof(string), typeof(WebServiceActivity));

        public static readonly DependencyProperty StatusIdProperty =
            DependencyProperty.Register("StatusId", typeof(string), typeof(WebServiceActivity));
        #endregion

        #region Properties
        public WorkflowContext __Context
        {
            get { return (WorkflowContext)GetValue(__ContextProperty); }
            set { SetValue(__ContextProperty, value); }
        }

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        [Browsable(true)]
        public string Address
        {
            get { return (string)GetValue(AddressProperty); }
            set { SetValue(AddressProperty, value); }
        }

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        [Browsable(true)]
        public string StatusId
        {
            get { return (string)GetValue(StatusIdProperty); }
            set { SetValue(StatusIdProperty, value); }
        }

        #endregion

        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                var listItem = this.__Context.Web.GetListItem(this.__Context.CurrentItemUrl);
                var requestId = listItem["RequestId"];

                // rest of code removed for brevity
            });
            return ActivityExecutionStatus.Closed;
        }
    }
}

Unfortunately, this.__Context.Web.GetListItem(this.__Context.CurrentItemUrl) always returns null, even though this.__Context.CurrentItemUrl has a valid value (e.g. "http://{Server Name}/Lists/{List Name}/DispForm.aspx?ID=9")

Am I doing something wrong?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

I have never had luck using SPWeb.GetListItem...I've used the following in the past when dealing with WorkflowContext objects:

SPListItem item = __Context.Web.Lists[new Guid(__Context.ListId)].GetItemById(__Context.ItemId);

Should do the trick.

share|improve this answer
1  
+1, that is how I do it too: stackoverflow.com/questions/1243736/… –  Kit Menke Aug 4 '11 at 19:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.