SPSecurity.RunWithElevatedPrivileges Method (Microsoft.ShareP...
Popularity Report
![]() |
|||
![]() |
|||
![]() |
|||
![]() |
|||
![]() |
|||
![]() |
URL Tag Cloud
Bookmark History
Saved by 2 people (0 private), first by anonymouse user on 2008-05-13
- Sukebeta on 2009-01-29 - Tags sharepoint , impersonation , tricks
- Ejwettstein on 2008-05-13 - Tags no_tag
Public Sticky notes
public class Worker
{
public Worker()
{ } private SPSite site = null;
private SPWeb web = null;
private SPFolder folder = null; /// <summary>
/// This Method is called throug Delegate elevatedGetSite which is definend in cmdOpenCnn_Click
/// </summary>
private void EstablishSharepoint()
{
site = new SPSite("http://srv-moss-tp1:36000");
web = site.OpenWeb();
}
/// <summary>
/// If you click the Button to establish a connection to your SharePoint-Site,
/// you run this code with elevated Privileges.
/// </summary>
private void cmdOpenCnn_Click(object sender, EventArgs e)
{
SPSecurity.CodeToRunElevated elevatedGetSite = new SPSecurity.CodeToRunElevated(EstablishSharepoint);
SPSecurity.RunWithElevatedPrivileges(elevatedGetSite); // After code execution in EstablishSharepoint(), following code will be executed
// and fills a TreeView (tv in this example) with all First-Level-Folders and their Subfolders TreeNode MainNode = new TreeNode("Web-Folders");
TreeNode n = null;
int index = 0; foreach (SPFolder f in web.Folders)
{
n = new TreeNode();
n.Text = f.Name;
n.Tag = f.ParentWeb.Url + "/" + f.Url;
n.ToolTipText = f.ParentWeb.Url + "/" + f.Url;
index = MainNode.Nodes.Add(n); foreach (SPFolder sf in f.SubFolders)
{
n = new TreeNode();
n.Text = sf.Name;
n.Tag = sf.ParentWeb.Url + "/" + sf.Url;
n.ToolTipText = sf.ParentWeb.Url + "/" + sf.Url;
MainNode.Nodes[index].Nodes.Add(n);
}
}
tv.Nodes.Add(MainNode);
}
Highlighted by ejwettstein


Public Comment