2011-01-28 8 views
0

更新: アウト変数を作成するにはどうすればよいですか?エラーが発生しました... 依存関係プロパティ 'ListItem'のエラータイプ 'System.Int32'が値タイプ 'System.String'と一致しません。 パラメータ名:値カスタムワークフローアクティビティでOUTパラメータを使用しているときにエラーが発生しました

using System; 
using System.ComponentModel; 
using System.ComponentModel.Design; 
using System.Collections; 
using System.Drawing; 
using System.Linq; 
using System.Workflow.ComponentModel.Compiler; 
using System.Workflow.ComponentModel.Serialization; 
using System.Workflow.ComponentModel; 
using System.Workflow.ComponentModel.Design; 
using System.Workflow.Runtime; 
using System.Workflow.Activities; 
using System.Workflow.Activities.Rules; 
using Microsoft.SharePoint.WorkflowActions; 
using Microsoft.SharePoint; 
using Microsoft.SharePoint.Workflow; 
using System.Diagnostics; 


namespace TestEmailDistributionActivity 
{ 
    public partial class Activity1: SequenceActivity 
    { 
     EventLog _log = new EventLog("Email Distribution"); 
     SPList _list; 
     SPFieldUserValueCollection objUserFieldValueCol; 
     string semailsettingKeyword1; 
     string semailsettingKeyword2; 
     string sender; 
     string semailsubject; 
     string semailfrom; 
     string toField; 

     public Activity1() 
     { 
      InitializeComponent(); 
     } 
     public static DependencyProperty __ContextProperty = DependencyProperty.Register("__Context", typeof(WorkflowContext), typeof(Activity1)); 
     [DescriptionAttribute("__Context")] 
     [BrowsableAttribute(true)] 
     [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)] 
     public WorkflowContext __Context 
     { 
      get 
      { 
       return ((WorkflowContext)(base.GetValue(Activity1.__ContextProperty))); 
      } 
      set 
      { 
       base.SetValue(Activity1.__ContextProperty, value); 
      } 
     } 
     public static DependencyProperty ListIdProperty = DependencyProperty.Register("ListId", typeof(string), typeof(Activity1)); 
     [DescriptionAttribute("ListId")] 
     [BrowsableAttribute(true)] 
     [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)] 
     public string ListId 
     { 
      get 
      { 
       return ((string)(base.GetValue(Activity1.ListIdProperty))); 
      } 
      set 
      { 
       base.SetValue(Activity1.ListIdProperty, value); 
      } 
     } 
     public static DependencyProperty ListItemProperty = DependencyProperty.Register("ListItem", typeof(int), typeof(Activity1)); 
     [DescriptionAttribute("ListItem")] 
     [BrowsableAttribute(true)] 
     [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)] 
     public int ListItem 
     { 
      get 
      { 
       return ((int)(base.GetValue(Activity1.ListItemProperty))); 
      } 
      set 
      { 
       base.SetValue(Activity1.ListItemProperty, value); 
      } 
     } 
     public static DependencyProperty RecipientsProperty = DependencyProperty.Register("Recipients", typeof(string), typeof(Activity1)); 
     [DescriptionAttribute("Recipients")] 
     [BrowsableAttribute(true)] 
     [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)] 
     public string Recipients 
     { 
      get 
      { 
       return ((string)(base.GetValue(Activity1.RecipientsProperty))); 
      } 
      set 
      { 
       base.SetValue(Activity1.ListItemProperty, value); 
      } 
     } 
     protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) 
     { 

      _log.Source = "Share Point Workflows"; 
      // _log.WriteEntry("Code entered into Excute Method"); 
      try   
      {     
       //Execute method as a elevated method 
       SPSecurity.CodeToRunElevated elevatedExecuteMethod = new SPSecurity.CodeToRunElevated(ExecuteMethod); 
       SPSecurity.RunWithElevatedPrivileges(elevatedExecuteMethod); 
      }   
      catch (Exception ex)  
      {   
       _log.WriteEntry("Error" + ex.Message.ToString(), EventLogEntryType.Error); 
      } 
      return ActivityExecutionStatus.Closed; 
     } 
     private void ExecuteMethod() 
     { 
      // _log.WriteEntry("Code entered into ExcuteMethod()"); 
      //retrieveing the Site object  
      SPSite _site = new SPSite(__Context.Site.ID); 
      //retrieveing the Web object    
      //SPWeb _web = (SPWeb)(__Context.Web); 
      SPWeb _web = _site.OpenWeb(__Context.Web.ID); 
      //retrieveing the list object   
      _list = _web.Lists[new Guid(this.ListId)]; 
      //retrieveing the list item object   
      SPListItem _listItem = _list.GetItemById(this.ListItem); 
      try 
      { 
       using (SPSite mysite = new SPSite("http://dlglobaltest.dl.com/Admin/IT/Application%20Development%20Group/TestEmailDistribution")) 
       { 
        using (SPWeb myweb = mysite.OpenWeb()) 
        { 
         _log.WriteEntry("message from activity"); 
         semailsubject = _listItem["E-Mail Subject"].ToString(); 
         semailfrom = _listItem["emalfrom"].ToString(); 
         SPList settingsList = myweb.Lists["Settings"]; 
         //SPListItem _settingslistItem = settingsList.GetItemById(this.ListItem); 
         //string sender = _settingslistItem["Sender"].ToString(); 
         SPQuery oQuery = new SPQuery(); 
         oQuery.Query = "<Where><Contains><FieldRef Name='Sender' /><Value Type='Text'>[email protected]</Value></Contains></Where>"; 
         SPListItemCollection ColListItems = settingsList.GetItems(oQuery); 
         foreach (SPListItem oListItem in ColListItems) 
         { 
          semailsettingKeyword1 = oListItem["Keyword1"].ToString(); 
          semailsettingKeyword2 = oListItem["Keyword2"].ToString(); 
          sender = oListItem["Sender"].ToString(); 
          //SPFieldUserValue objUserFieldValue = new SPFieldUserValue(myweb, oListItem["Recipients"].ToString()); 

          if ((semailsubject.Contains(semailsettingKeyword1)) || (semailsubject.Contains(semailsettingKeyword2))) 
          { 
           objUserFieldValueCol = new SPFieldUserValueCollection(myweb, oListItem["Recipients"].ToString()); 
           for (int i = 0; i < objUserFieldValueCol.Count; i++) 
           { 
            toField = objUserFieldValueCol[i].User.Email; 
            this.Recipients = toField.ToString();//**getting the error here.** 

           } 
           _log.WriteEntry(toField); 

          } 
         } 
        } 
       } 
      } 
      catch (Exception ex) 
      { 
       _log.WriteEntry("Error" + ex.Message.ToString(), EventLogEntryType.Error); 
      } 

     } 
    } 
} 

アクションファイル:

<Action Name="get Recipients" 
      ClassName="TestEmailDistributionActivity.Activity1" 
      Assembly="TestEmailDistributionActivity, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ef7ee5e33fadc78e" 
      AppliesTo="all" Category="Custom"> 
     <RuleDesigner Sentence="get all column values from %1 and %3 from Settings list"> 
      <FieldBind Field="ListId,ListItem" Text="this list" Id="1" DesignerType="ChooseListItem" /> 
      <FieldBind Field="Recipients" Text="get Recipients" Id="1" DesignerType="ParameterNames" /> 
     </RuleDesigner> 
     <Parameters> 
      <Parameter Name="__Context" Type="Microsoft.SharePoint.WorkflowActions.WorkflowContext" Direction="In" /> 
      <Parameter Name="ListId" Type="System.String, mscorlib" Direction="In" /> 
      <Parameter Name="ListItem" Type="System.Int32, mscorlib" Direction="In" /> 
      <Parameter Name="Recipients" Type="System.String, mscorlib" Direction="Out" /> 
     </Parameters> 
    </Action> 

おかげで、このコードが間違っている

答えて

1

SPSite _site = new SPSite(__Context.Site.Url); 
SPWeb _web = (SPWeb)(__Context.Web); 

上昇コンテキストで動作し、あなたはもう一度サイトとウェブを作成します。サイトは再作成しましたが、Webは再作成していません。したがって、Webは間違ったコンテキストでサイトを参照している可能性があります。

私は通常ちょうど(あなたが使用してオブジェクトを配置してください)

SPSite _site = new SPSite(__Context.Site.Id); 
SPWeb _web = _site.OpenWeb(__Context.Web.Id); 
+0

私はsuggetionごとにコードを変更しましたが、今は値をハードコードしようとしています。すべてがうまくいきましたが、コードでoutパラメータを使用する方法がわかりません。私は自分のコードを更新しました。 – user346514

0

user346514からのコードはほとんどの作業だけに注意を払って行います

public string Recipients 
     { 
      get 
      { 
       return ((string)(base.GetValue(Activity1.RecipientsProperty))); 
      } 
      set 
      { 
       base.SetValue(Activity1.ListItemProperty, value); 
      } 
     } 

にする必要があります:

public string Recipients 
     { 
      get 
      { 
       return ((string)(base.GetValue(Activity1.RecipientsProperty))); 
      } 
      set 
      { 
       base.SetValue(Activity1.RecipientsProperty, value); 
      } 
     } 

また、ACTIONSファイル:

%3が一致し、同じ順序でなら、

<RuleDesigner Sentence="get all column values from %1 and %2 from Settings list. Store result on %3."> 
       <FieldBind Field="ListId,ListItem" Text="this list" Id="1" DesignerType="ChooseListItem" /> 
<FieldBind Field="ListId2,ListItem2" Text="this list" Id="2" DesignerType="ChooseListItem" /> 
<FieldBind Field="Recipients" Text="get Recipients" Id="3" DesignerType="ParameterNames" /> 
      </RuleDesigner> 

% 1、%2:

<RuleDesigner Sentence="get all column values from %1 and %3 from Settings list"> 
      <FieldBind Field="ListId,ListItem" Text="this list" Id="1" DesignerType="ChooseListItem" /> 
      <FieldBind Field="Recipients" Text="get Recipients" Id="1" DesignerType="ParameterNames" /> 
     </RuleDesigner> 

のようなものでなければなりません。 これらのフィールドも同じ順序で定義する必要がありますが、同じ順序は必要ありません。

私はそれが古い投稿だと知っていますが、誰かがOUTパラメータでワークフローアクティビティの例を必要とする場合に備えて、

関連する問題