views:

916

answers:

1

I have built a method to pull some UserProfile information out of SharePoint. It works great in C#, but I can't figure out how to convert one part of it to VB.NET. I'm not that great at VB but usually the basic code converters online get me past any problem I have. The problem is concerning the SPSecurity.RunWithEleveatedPrivilages section below. Does any one know how to implement the delegate code in VB?

 public List<MyData> GetData(string id)
 {
     List<MyData> mylinks = new List<MyData>();
     SPSecurity.RunWithElevatedPrivileges(delegate
     {    
         var mgr = new UserProfileManager(ServerContext.GetContext("MySSP"));
         UserProfile profile = null;
         try
         {
             profile = mgr.GetUserProfile(id);
         }
         catch { }

         QuickLinkManager qlmgr = new QuickLinkManager(profile);
         QuickLink[] ql = qlmgr.GetItems();

         for (int i = 0; i < ql.Length; i++)
         {
              mylinks.Add(new MyData(ql[i].Url, ql[i].Title));
         }
     });
     return mylinks;

}

Josh

+1  A: 

Create a new delegate with that function. (not an anonymous one)

Then use SPSecurity.RunWithElevatedPrivileges(New DelegateName(Addressof yourfunction))

Maybe there is better way in .NET 3.0+ I'm not sure

dr. evil
Thanks I will try that.
Omenof
You can use the SPSecurity.CodeToRunElevated delegate. Populating your list from within the delegate will require a closure: http://blogs.msdn.com/vbteam/archive/2007/05/02/closures-in-vb-part-1.aspx
dahlbyk