2
我正在为Sharepoing 2010制作一个简单的生日日历webpart。在为Sharepoint 2010 UserProfiles做foreach时,有没有办法对它们进行排序?
我需要遍历网站的所有用户并显示那些在该日期有生日的人。我需要按用户姓名的字母顺序呈现用户。
我可以做这个ILKE通过用户列表进行迭代:
SPSite currentSite = ...
ServerContext ospServerContext = ServerContext.GetContext(currentSite);
UserProfileManager ospUserProfileManager = new UserProfileManager(ospServerContext);
foreach (UserProfile ospUserProfile in ospUserProfileManager) { ... }
但是,后来我就在配置文件的顺序无法控制。是否有任何内置的方式来通过一些简单的规则排序配置文件,或者我必须做一个Dictionary(字符串,UserProfile),从UserProfileManager填充它,然后按键排序,然后对其成员进行foreach?
谢谢!
嗯它的奇怪,但VS2010抱怨OrderBy不是列表的有效成员...我做错了什么? –
Istrebitel
在答案更新中添加*使用*块。 –
如果你打算去LINQ路线,那么你可以去整个猪群,并使用'var collection = ospUserProfileManager.Cast().ToList()'而不是'foreach'循环,或者更好的办法是去直接从'Cast'转换为'OrderBy'而不用创建List。并在'OrderBy'之前进行生日过滤'Where'以提高效率... –
Rawling