2009-08-07 18 views
11

Paylaşım noktası iş akışı için özel etkinlik yazıyorum ve geçerli iş akışı öğesi SPWeb veya SPSite'yi nasıl kullanabileceğimi bilmiyorum.İş akışı etkinliğinde (SharePoint) içerik öğesi nasıl alınır?

http://blogs.microsoft.co.il/blogs/davidbi/archive/2008/07/21/How-to-get-the-context-item-in-workflow-activity-sharepoint.aspx'u görüyorum, ancak bu çözümün xml rutinleri benim için çok kötü.

Belki de iş akışı etkinliğinde içerik öğesi almak için başka bir kod çözümü var mı?

+0

Burada anlatılan her şeyi yaptım ve yine de bağlamım her zaman boş. SequenceActivity tabanlı bir özel SPDesigner Etkinliği kodluyorum. Daha da fazlası, WF'yi Sharepoint Designer'da düzenlemeyi denediğimde, bir hata nedeniyle onu kaydedemiyorum. –

cevap

18

Bunun cevabı birkaç adım uzaklıktadır: SPD eşlemek bilir böylece

  1. (sizin .actions dosyasında Özel Etkinlik .cs
  2. Link özelliklerini özellikleri ekleyin senin özellikleri)
  3. kodunuzdaki özelliklerini kullanın

ADIM 1: İşte kod içindir

public static DependencyProperty __ContextProperty = System.Workflow.ComponentModel.DependencyProperty.Register("__Context", typeof(WorkflowContext), typeof(GetEmails)); 

[Description("The site context")] 
[Category("User")] 
[Browsable(true)] 
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] 
public WorkflowContext __Context 
{ 
    get 
    { 
     return ((WorkflowContext)(base.GetValue(GetEmails.__ContextProperty))); 
    } 
    set 
    { 
     base.SetValue(GetEmails.__ContextProperty, value); 
    } 
} 

public static DependencyProperty __ListIdProperty = System.Workflow.ComponentModel.DependencyProperty.Register("__ListId", typeof(string), typeof(GetEmails)); 

[ValidationOption(ValidationOption.Required)] 
public string __ListId 
{ 
    get 
    { 
     return ((string)(base.GetValue(GetEmails.__ListIdProperty))); 
    } 
    set 
    { 
     base.SetValue(GetEmails.__ListIdProperty, value); 
    } 
} 

public static DependencyProperty __ListItemProperty = System.Workflow.ComponentModel.DependencyProperty.Register("__ListItem", typeof(int), typeof(GetEmails)); 

[ValidationOption(ValidationOption.Required)] 
public int __ListItem 
{ 
    get 
    { 
     return ((int)(base.GetValue(GetEmails.__ListItemProperty))); 
    } 
    set 
    { 
     base.SetValue(GetEmails.__ListItemProperty, value); 
    } 
} 

public static DependencyProperty __ActivationPropertiesProperty = DependencyProperty.Register("__ActivationProperties", typeof(Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties), typeof(GetEmails)); 

[ValidationOption(ValidationOption.Required)] 
public Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties __ActivationProperties 
{ 
    get 
    { 
     return (Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties)base.GetValue(GetEmails.__ActivationPropertiesProperty); 
    } 
    set 
    { 
     base.SetValue(GetEmails.__ActivationPropertiesProperty, value); 
    } 
} 

ADIM 2: özellikleri (sınıfım size sınıf olmak adlandırmak gerekir GetEmails adlı) Sonra .actions içinde dikkat (bu mülkler için bloğuna eşleştirmeleri eklemek dosyası __ListID, __ListItem, __Context için girdileri ve __ActivationProperties):

<Action Name="[DESCRIPTION OF YOUR ACTION]" 
    ClassName="[Your.Namespace.Goes.Here].GetEmails" 
    Assembly="[yourDLLName], Version=1.0.0.0, Culture=neutral, PublicKeyToken=0bfc6fa4c4aa913b" 
    AppliesTo="all" 
    Category="[Your Category Goes Here]"> 
    <RuleDesigner Sentence="[blah blah blah]"> 
    <FieldBind Field="PeopleFieldName" Text="people field" Id="1"/> 
    <FieldBind Field="Output" Text="emailAddress" Id="2" 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="PeopleFieldName" Type="System.String, mscorlib" Direction="In" /> 
    <Parameter Name="Output" Type="System.String, mscorlib" Direction="Out" /> 
    <Parameter Name="__ActivationProperties" Type="Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties, Microsoft.SharePoint" Direction="Out" /> 
    </Parameters> 
</Action> 

ADIM 3:

: Burada bir örnek işlevi yürütmek edilir
+0

Teşekkürler, bu çözüm bana yardımcı oldu. – avishnyakov

+0

Mükemmel ve kapsamlı bir cevap. Teşekkürler! –

+0

Teşekkürler! ActivationProperties'e ne zaman ihtiyacımız var? – Serhiy

2

Kiti Menke cevabı çok kapsamlı ve adil kapsar hakkında tüm ihtiyacınız: Bunun yerine

SPWeb tmpweb = __Context.Web; 
SPSite site = new SPSite(tmpweb.Url); 
SPWeb web = site.OpenWeb(); 

:

Bunu yaparsanız ben yalnızca aşağıdaki ...

eklersiniz

daha sonra, onu tetikleyen kişi tarafından iş akışına iletilen güvenlik bağlamından kurtulmuşsunuzdur.

1

Bu kodu deneyin ve contex nesnesini her zaman boş olarak çalıştırın. bir tane nedenini biliyor mu?

protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) 
    { 


     //return base.Execute(executionContext); 
     int IdRetorno = -1; 



     try { 
      SPSecurity.RunWithElevatedPrivileges(delegate 
      { 
       LogExceptionToWorkflowHistory("Inicio:", executionContext, WorkflowInstanceId); 
       using (SPSite sitio = new SPSite(this.__Context.Site.ID)) 
       { 

        using (SPWeb web = sitio.AllWebs[this.__Context.Site.ID]) 
        { 


         SPList sourceList = web.Lists[new Guid(ListId)]; 
         LogExceptionToWorkflowHistory(ListId, executionContext, WorkflowInstanceId); 
         SPList destinoList = web.Lists[new Guid(SourceListId)]; 
         LogExceptionToWorkflowHistory(SourceListId, executionContext, WorkflowInstanceId); 
         SPListItem sourceItem = sourceList.Items.GetItemById(ListItem); 
         LogExceptionToWorkflowHistory(ListItem.ToString(), executionContext, WorkflowInstanceId); 

         SPListItem destinoItem = destinoList.Items.Add(); 
         CopyFieldValues(sourceItem, destinoItem); 
         destinoItem.SystemUpdate(); 

         sourceItem.Delete(); 
         IdRetorno = destinoItem.ID; 
        } 
       } 

      }); 

     } 
     catch (Exception ex) { 
      if (!System.Diagnostics.EventLog.SourceExists("MyApp1")) 
       System.Diagnostics.EventLog.CreateEventSource(
        "MyApp1", "Application"); 

      EventLog EventLog1 = new EventLog(); 
      EventLog1.Source = "MyApp1"; 
      EventLog1.WriteEntry(ex.Message,EventLogEntryType.FailureAudit); 

      LogExceptionToWorkflowHistory(ex.Message, executionContext, WorkflowInstanceId); 
     } 


     OutListItemID = IdRetorno; 




     return base.Execute(executionContext); 

    } 

sayesinde

+0

Benim tahmin RunWithElevatedPrivileges içinde sarılmış çünkü blok. Siteyi başka bir şekilde geçmek zorunda kalacaksınız. –

1

bu çok kolay olmadığını bilmiyorum, ama ben kullandı:

objCurrentItem = workflowProperties.Item 

iş akışı (listesi) içinde öğeyi almak için ve daha sonra değiştirmek için Listedeki öğeler

3

Bu, 2010 API'sinde bir değişiklik olup olmadığından emin değilim ancak __Context özelliği, liste ve öğe de dahil olmak üzere gerekli tüm parçaları sağlar. Aşağıdaki örnekte, davek'in güvenlik bağlamını atmak için önerisi:

  var contextWeb = __Context.Web; 
      var site = new SPSite(contextWeb.Url); 
      var web = site.OpenWeb(); 

      var list = web.Lists[new Guid(__Context.ListId)]; 
      var item = list.GetItemById(__Context.ItemId); 
İlgili konular