SPSecurity.RunWithElevatedPrivileges(
delegate()
{
using (SPSite site = new SPSite(SPContext.Current.Site.ID))
using (SPWeb web = site.OpenWeb(SPContext.Current.Web.ID))
string ItemID = web.Lists["myList"].Items[0]["ItemID"].ToString();
}
); SPSecurity.RunWithElevatedPrivileges(
delegate()
{
using (SPSite site = new SPSite(http://server/))
using (SPWeb web = site.OpenWeb("myweb"))
string ItemID = web.Lists["myList"].Items[0]["ItemID"].ToString();
}
);SPWeb webContext = null; //declare webContext out side the try ... catch and assign "null"
try
{
webContext = SPContext.Current.Web; // Assign SPContext to the webContext
SPSecurity.RunWithElevatedPrivileges(
delegate()
{
using (SPSite site = new SPSite(webContext.Site.ID))
using (SPWeb web = site.OpenWeb(webContext.ID))
string ItemID = web.Lists["myList"].Items[0]["ItemID"].ToString();
}
);
}
catch (Exception ex)
{
}
finally
{
if (webContext != null)
webContext.Dispose();
}
Utilizadores a navegar neste fórum: Nenhum utilizador registado e 1 visitante