سؤال

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?

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى sharepoint.stackexchange
scroll top