Wednesday, 27 July 2011

Receiving datas from MasterPage gallary

Guid currentSiteGuid = SPContext.Current.Site.ID;
using (SPSite site = new SPSite(currentSiteGuid))
{
using (SPWeb web = site.OpenWeb())
{
SPQuery query = new SPQuery();
query.Query = "<Where><Eq><FieldRef Name='FileLeafRef' /><Value Type='Text'>Insidedefault.master</Value></Eq></Where>";
Microsoft.SharePoint.SPList gallery1 = site.GetCatalog(Microsoft.SharePoint.SPListTemplateType.MasterPageCatalog);
SPListItemCollection col = gallery1.GetItems(query);
if (col.Count > 0)
{
foreach (SPListItem item in col)
{
//web.AllowUnsafeUpdates = true;
item.Web.AllowUnsafeUpdates = true;
item.File.CheckOut();
item.File.CheckIn("check in");
item.File.Publish("publish");
item.File.Approve("dsf");
web.Update();
// item.Web.AllowUnsafeUpdates = true;
//web.AllowUnsafeUpdates = false;
}
}
}
}

No comments:

Post a Comment