2011-06-28 24 views
0

我想从C#访问用户箱里,这样我可以通过所有在他箱里的物品的循环和更新工作流状态的项目的每个版本。编程访问Sitecore的用户箱里

我使用Sitecore的6.2.0(修订版101105)

感谢您的关注!

回答

4

编辑:下面的代码需要在主上下文下运行 - “从sitecore admin内部”。如果您是从Web上下文(网站上的页面)运行它并且Context.Database是“web”,则需要使用Factory.GetDatabase(“master”)替换Sitecore.Context.Database的所有实例。


首先,你需要把所有的工作流程

Sitecore.Context.Database.WorkflowProvider.GetWorkflows(); 

随后的foreach的工作流程,你需要把所有的状态:

workflow.GetStates(); 

然后每个状态,你可以得到所有的项目

var itemDataUris = workflow.GetItems(state); 

GetItems返回dataUris 列表所以,如果你正在使用有问题的用户登录后,您可以做

foreach (var dataUri in itemDataUris) 
{ 
    var item = Context.Database.GetItem(dataUri); 
    //check if the item is null (if null the user doesn't have access to it 
    if (item != null) 
     usersWorkflowItems.Add(item); //Here you also need to somehow add which state the item is in 
} 

如果正在运行作为管理员,并希望得到该项目另一位用户,您需要将上述代码包装在UserSwitcher中

Sitecore.Security.Accounts.UserSwitcher.Enter(Sitecore.Security.Accounts.User.FromName("sitecore\User", true)); 
foreach (var dataUri in itemDataUris) 
    { 
     var item = Context.Database.GetItem(dataUri); 
     //check if the item is null (if null the user doesn't have access to it 
     if (item != null) 
      usersWorkflowItems.Add(item); //Here you also need to somehow add which state the item is in 
    } 
Sitecore.Security.Accounts.UserSwitcher.Exit(); 

希望对您有所帮助!

+0

确保你不是试图运行在网络背景下,这个代码...它不会工作。 – Bryan

+0

谢谢Brian。我会修改答案,以确保它说明。 – marto

+0

marto,非常感谢你为你详细的解释。这正是我需要的! – DougCouto

2

不知道在您的代码运行,或多久的情况下,但你可以利用从用户箱里的RSS源?

+0

不错的选择的API +1 – Younes