2015-10-13 51 views

回答

4

可以在uiUpload管道檢查,但不會針對編程創建的項目,即它只會在用戶通過CMS接口上傳的物品火災。

創建一個新的處理器類:

public class ExternalSystemProcessor 
{ 
    public void Process(UploadArgs args) 
    { 
     foreach (Item file in args.UploadedItems.Where(file => file.Paths.IsMediaItem)) 
     { 
      // Custom code here 
      SaveToExternalSystem(file.ID); 
     } 
    } 
} 

然後修補後在默認保存處理器:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/"> 
    <sitecore> 
    <processors> 
     <uiUpload> 
     <processor type="MyProject.Custom.Pipelines.ExternalSystemProcessor, MyProject.Custom" mode="on" 
        patch:after="*[@type='Sitecore.Pipelines.Upload.Save, Sitecore.Kernel']" /> 
     </uiUpload> 
    </processors> 
    </sitecore> 
</configuration> 
1

我不記得在新項目上傳到媒體庫時將執行的任何管道,但您應該能夠使用item:created事件。

只需檢查args中的項目(ItemCreatedEventArgs)是否爲媒體項目並執行您的代碼。

public void OnItemCreated(object sender, EventArgs args) 
{ 
    var createdArgs = Event.ExtractParameter(args, 0) as ItemCreatedEventArgs; 

    if (createdArgs != null) 
    { 
     if (createdArgs.Item != null) 
     { 
     ... 
     } 
    } 
} 
+0

可以檢查的項目是使用'item.Paths.IsMediaItem'媒體 – jammykam

相關問題