本文整理汇总了C#中SPFeatureReceiverProperties.GetWeb方法的典型用法代码示例。如果您正苦于以下问题:C# SPFeatureReceiverProperties.GetWeb方法的具体用法?C# SPFeatureReceiverProperties.GetWeb怎么用?C# SPFeatureReceiverProperties.GetWeb使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SPFeatureReceiverProperties
的用法示例。
在下文中一共展示了SPFeatureReceiverProperties.GetWeb方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeleteWebParts
/// <summary>
/// Delete webparts.
/// </summary>
/// <param name="properties"></param>
private static void DeleteWebParts(SPFeatureReceiverProperties properties)
{
try
{
//System.Diagnostics.Debugger.Launch(); you need to use stsadm for launch debugger
if (properties.Definition.Properties["WebPartsToDelete"] != null
&& !String.IsNullOrEmpty(properties.Definition.Properties["WebPartsToDelete"].Value))
{
using (SPWeb web = properties.GetWeb())
{
SPList list = web.GetCatalog(SPListTemplateType.WebPartCatalog);
if (list != null)
{
string[] wpToDelete = properties.Definition.Properties["WebPartsToDelete"].Value.Split(',');
IEnumerable<SPListItem> wpToDeleteList = list.Items.OfType<SPListItem>().Where(it => wpToDelete.Contains(it.Name));
if (wpToDeleteList.Count() > 0)
{
foreach (SPListItem toDelete in wpToDeleteList)
{
list.Items.DeleteItemById(toDelete.ID);
}
}
}
}
}
}
catch (Exception ex)
{
throw new Exception("Receivers.WebPartsReceiver.DeleteWebParts problem", ex);
}
}
示例2: SetDefaultMasterPage
/// <summary>
/// Set Default MasterPage.
/// </summary>
/// <param name="properties"></param>
/// <param name="activation">if deactivation : set the original master / if activation : set the custom master.</param>
private static void SetDefaultMasterPage(SPFeatureReceiverProperties properties, bool activation)
{
try
{
//System.Diagnostics.Debugger.Launch();
using (SPWeb web = properties.GetWeb())
{
string urlCustomMaster = "/_catalogs/masterpage/BaseAppMasterPage.master";
string urlDefaultMaster = "/_catalogs/masterpage/default.master";
string masterName = string.Empty;
if (activation)
{
masterName = urlCustomMaster;
Uri masterUri = new Uri(web.Url + masterName);
web.MasterUrl = masterUri.AbsolutePath;
web.CustomMasterUrl = masterUri.AbsolutePath;
web.Update();
}
else
{
masterName = urlDefaultMaster;
Uri masterUri = new Uri(web.Url + masterName);
web.MasterUrl = masterUri.AbsolutePath;
web.CustomMasterUrl = masterUri.AbsolutePath;
web.Update();
// if necessary remove the custom master page.
SPFolder catalogsFolder = web.Folders["_catalogs"];
if (catalogsFolder != null)
{
SPFolder masterpageFolder = catalogsFolder.SubFolders["masterpage"];
if (masterpageFolder != null)
{
SPFile custMPFile = masterpageFolder.Files["BaseAppMasterPage.master"];
if (custMPFile != null)
{
custMPFile.Delete();
}
}
}
web.Update();
}
}
}
catch (Exception ex)
{
throw new Exception("Receivers.MasterPageReceiver.SetDefaultMasterPage problem", ex);
}
}
示例3: AddListItems
/// <summary>
/// Add default items to list.
/// </summary>
/// <param name="properties"></param>
private static void AddListItems(SPFeatureReceiverProperties properties)
{
try
{
using (SPWeb web = properties.GetWeb())
{
// add default item to the BaseList
SPList baseList = web.Lists.TryGetList("BaseList");
if (baseList != null)
{
SPListItem item = baseList.Items.Add();
item["Title"] = "Sample 1";
item["Content"] = "Sample 1 Content";
item.Update();
SPListItem item2 = baseList.Items.Add();
item2["Title"] = "Sample 2";
item2["Content"] = "Sample 2 Content";
item2.Update();
SPListItem item3 = baseList.Items.Add();
item3["Title"] = "Sample 3";
item3["Content"] = "Sample 3 Content";
item3.Update();
SPListItem item4 = baseList.Items.Add();
item4["Title"] = "Sample 4";
item4["Content"] = "Sample 4 Content";
item4.Update();
SPListItem item5 = baseList.Items.Add();
item5["Title"] = "Sample 5";
item5["Content"] = "Sample 5 Content";
item5.Update();
}
}
}
catch (Exception ex)
{
throw new Exception("Receivers.ListsReceiver.AddListItems problem", ex);
}
}
示例4: DeleteLists
/// <summary>
/// Delete lists.
/// </summary>
/// <param name="properties"></param>
private static void DeleteLists(SPFeatureReceiverProperties properties)
{
try
{
if (properties.Definition.Properties["ListsToDelete"] != null
&& !String.IsNullOrEmpty(properties.Definition.Properties["ListsToDelete"].Value))
{
using (SPWeb web = properties.GetWeb())
{
// loop on all lists name to delete
// <Feature>
// ...
// <Properties>
// <Property Key="ListsToDelete" Value="NameOfListToDelete"/>
// </Properties>
// </Feature>
foreach (string filename in properties.Definition.Properties["ListsToDelete"].Value.Split(','))
{
SPList list = web.Lists.TryGetList(filename);
if (list != null)
{
list.Delete();
}
}
}
}
}
catch (Exception ex)
{
throw new Exception("Receivers.ListsReceiver.DeleteLists problem", ex);
}
}