本文整理汇总了C#中SPWeb.GetLimitedWebPartManager方法的典型用法代码示例。如果您正苦于以下问题:C# SPWeb.GetLimitedWebPartManager方法的具体用法?C# SPWeb.GetLimitedWebPartManager怎么用?C# SPWeb.GetLimitedWebPartManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SPWeb
的用法示例。
在下文中一共展示了SPWeb.GetLimitedWebPartManager方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddWebPartToPage
public static string AddWebPartToPage(SPWeb web, string pageUrl, string webPartName, string zoneID, int zoneIndex)
{
try
{
web.AllowUnsafeUpdates = false;
using (SPLimitedWebPartManager webPartManager = web.GetLimitedWebPartManager(pageUrl, System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared))
{
using (var webPart = CreateWebPart(web, webPartName, webPartManager))
{
if (webPart != null)
{
webPartManager.AddWebPart(webPart, zoneID, zoneIndex);
return webPart.ID;
}
}
}
}
catch (Exception ex)
{
// throw;
}
finally
{
web.AllowUnsafeUpdates = false;
}
return string.Empty;
}
示例2: AddWebPartToPage
/// <summary>
/// Add the web part to page.
/// </summary>
/// <param name="web">The web.</param>
/// <param name="pageUrl">The page URL.</param>
/// <param name="webPartName">Name of the web part.</param>
/// <param name="zoneID">The zone ID.</param>
/// <param name="zoneIndex">Index of the zone.</param>
/// <returns></returns>
public static string AddWebPartToPage(SPWeb web, string pageUrl, string webPartName, string zoneID, int zoneIndex, bool isHidden)
{
using (SPLimitedWebPartManager webPartManager = web.GetLimitedWebPartManager(
pageUrl, System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared))
{
using (System.Web.UI.WebControls.WebParts.WebPart webPart = CreateWebPart(web, webPartName, webPartManager, isHidden))
{
bool isExists = false;
foreach (System.Web.UI.WebControls.WebParts.WebPart wp in webPartManager.WebParts)
{
if (wp.Title.Equals(webPartName.Replace(".webpart", "")))
{
isExists = true;
break;
}
else
{
isExists = false;
}
}
if (!isExists)
{
webPartManager.AddWebPart(webPart, zoneID, zoneIndex);
}
return webPart.ID;
}
}
}
示例3: AddWebPartToPage
public static void AddWebPartToPage(SPWeb web, string pageUrl, string webPartName, string zoneId, int zoneIndex, bool flag)
{
try
{
// adding Web part if not exists on the workspace
using (WebPart webPart = CreateWebPart(web, webPartName))
{
Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager manager;
try
{
manager = web.GetLimitedWebPartManager(pageUrl, PersonalizationScope.Shared);
}
catch (Exception)
{
manager = null;
}
if (manager != null)
{
webPart.ChromeType = PartChromeType.None;
manager.AddWebPart(webPart, zoneId, zoneIndex);
// return webPart.ID;
manager.Dispose();
}
}
}
catch (Exception)
{
return;
}
}
示例4: AddXsltViewWebPart
public static void AddXsltViewWebPart(SPWeb web, SPList list, string pageUrl, string webPartName, string zoneID,
int zoneIndex, bool isHidden, string viewTitle)
{
using (SPLimitedWebPartManager webPartManager = web.GetLimitedWebPartManager(
pageUrl, System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared))
{
bool isExists = false;
foreach (System.Web.UI.WebControls.WebParts.WebPart wp in webPartManager.WebParts)
{
if (wp.Title.Equals(webPartName))
{
isExists = true;
break;
}
else
{
isExists = false;
}
}
if (!isExists)
{
XsltListViewWebPart webPart = new XsltListViewWebPart();
webPart.ListId = list.ID;
webPart.Title = webPartName;
webPart.ChromeType = System.Web.UI.WebControls.WebParts.PartChromeType.TitleAndBorder;
SPView view = list.Views[viewTitle];
webPart.ViewGuid = view.ID.ToString();
webPart.XmlDefinition = view.GetViewXml();
webPartManager.AddWebPart(webPart, zoneID, zoneIndex);
}
}
}
示例5: AssignJsLinkToListViews
public static void AssignJsLinkToListViews(SPWeb web, SPView view, string jsLink)
{
SPLimitedWebPartManager limitedWebPartManager = null;
XsltListViewWebPart providerWP = null;
try {
limitedWebPartManager = web.GetLimitedWebPartManager(view.Url, PersonalizationScope.Shared);
providerWP = (from Microsoft.SharePoint.WebPartPages.WebPart webPart in limitedWebPartManager.WebParts where webPart is XsltListViewWebPart select webPart).First() as XsltListViewWebPart;
providerWP.JSLink = jsLink;
limitedWebPartManager.SaveChanges(providerWP);
logger.Trace("jsLink "+ jsLink +" for" + view.Title + " assigned successfully");
}
catch (Exception ex) {
logger.Error("jsLink " + jsLink + " not assigned! With error: ", ex.Message);
}
finally {
if (limitedWebPartManager != null) {
if (limitedWebPartManager.Web != null) {
limitedWebPartManager.Web.Dispose();
}
limitedWebPartManager.Dispose();
}
providerWP.Dispose();
}
}
示例6: AddWebPartContentEditor
public static void AddWebPartContentEditor(SPWeb web, string pageUrl, string zoneID, int zoneIndex, string testForContentEditor, string link, PartChromeType cromeType, string title)
{
try
{
ContentEditorWebPart contentEditor = new ContentEditorWebPart();
XmlDocument xmlDoc = new XmlDocument();
XmlElement xmlElement = xmlDoc.CreateElement("HtmlContent");
xmlElement.InnerText = testForContentEditor;
contentEditor.Content = xmlElement;
using (SPLimitedWebPartManager manager =
web.GetLimitedWebPartManager(pageUrl, PersonalizationScope.Shared))
{
contentEditor.ChromeType = cromeType;
contentEditor.ContentLink = link;
contentEditor.Title = title;
manager.AddWebPart(contentEditor, zoneID, zoneIndex);
}
}
catch (Exception ee)
{
EssnLog.logInfo("Error on AddWebPartContentEditor in FeatureActivated.");
EssnLog.logExc(ee);
}
}
示例7: ReplaceValues
/// <summary>
/// Replaces the content of a <see cref="MediaWebPart"/> web part.
/// </summary>
/// <param name="web">The web that the file belongs to.</param>
/// <param name="file">The file that the web part is associated with.</param>
/// <param name="settings">The settings object containing user provided parameters.</param>
/// <param name="wp">The web part whose content will be replaced.</param>
/// <param name="regex">The regular expression object which contains the search pattern.</param>
/// <param name="manager">The web part manager. This value may get updated during this method call.</param>
/// <param name="wasCheckedOut">if set to <c>true</c> then the was checked out prior to this method being called.</param>
/// <param name="modified">if set to <c>true</c> then the web part was modified as a result of this method being called.</param>
/// <returns>The modified web part. This returned web part is what must be used when saving any changes.</returns>
internal static WebPart ReplaceValues(SPWeb web,
SPFile file,
Settings settings,
MediaWebPart wp,
Regex regex,
ref SPLimitedWebPartManager manager,
ref bool wasCheckedOut,
ref bool modified)
{
if (string.IsNullOrEmpty(wp.MediaSource) && string.IsNullOrEmpty(wp.TemplateSource) && string.IsNullOrEmpty(wp.PreviewImageSource))
return wp;
bool isMediaSourceMatch = false;
if (!string.IsNullOrEmpty(wp.MediaSource))
isMediaSourceMatch = regex.IsMatch(wp.MediaSource);
bool isTemplateSourceMatch = false;
if (!string.IsNullOrEmpty(wp.TemplateSource))
isTemplateSourceMatch = regex.IsMatch(wp.TemplateSource);
bool isPreviewImageSourceMatch = false;
if (!string.IsNullOrEmpty(wp.PreviewImageSource))
isPreviewImageSourceMatch = regex.IsMatch(wp.PreviewImageSource);
if (!isMediaSourceMatch && !isTemplateSourceMatch && !isPreviewImageSourceMatch)
return wp;
string mediaSourceContent = wp.MediaSource;
string templateSourceContent = wp.TemplateSource;
string previewImageSourceContent = wp.PreviewImageSource;
string mediaSourceResult = mediaSourceContent;
string templateSourceResult = templateSourceContent;
string previewImageSourceResult = previewImageSourceContent;
if (!string.IsNullOrEmpty(mediaSourceContent))
mediaSourceResult = regex.Replace(mediaSourceContent, settings.ReplaceString);
if (!string.IsNullOrEmpty(templateSourceContent))
templateSourceResult = regex.Replace(templateSourceContent, settings.ReplaceString);
if (!string.IsNullOrEmpty(previewImageSourceContent))
previewImageSourceResult = regex.Replace(previewImageSourceContent, settings.ReplaceString);
if (isMediaSourceMatch)
Logger.Write("Match found: File={0}, WebPart={1}, Replacement={2} => {3}",
file.ServerRelativeUrl, wp.Title, mediaSourceContent, mediaSourceResult);
if (isTemplateSourceMatch)
Logger.Write("Match found: File={0}, WebPart={1}, Replacement={2} => {3}",
file.ServerRelativeUrl, wp.Title, templateSourceContent, templateSourceResult);
if (isPreviewImageSourceMatch)
Logger.Write("Match found: File={0}, WebPart={1}, Replacement={2} => {3}",
file.ServerRelativeUrl, wp.Title, previewImageSourceContent, previewImageSourceResult);
if (!settings.Test)
{
if (file.CheckOutType == SPFile.SPCheckOutType.None)
{
file.CheckOut();
wasCheckedOut = false;
}
// We need to reset the manager and the web part because a checkout (now or from an earlier call)
// could mess things up so safest to just reset every time.
manager.Web.Dispose(); // manager.Dispose() does not dispose of the SPWeb object and results in a memory leak.
manager.Dispose();
manager = web.GetLimitedWebPartManager(file.Url, PersonalizationScope.Shared);
wp.Dispose();
wp = (MediaWebPart)manager.WebParts[wp.ID];
if (isMediaSourceMatch)
wp.MediaSource = mediaSourceResult;
if (isTemplateSourceMatch)
wp.TemplateSource = templateSourceResult;
if (isPreviewImageSourceMatch)
wp.PreviewImageSource = previewImageSourceResult;
modified = true;
}
return wp;
}
示例8: getJSLinkFromView
internal static string getJSLinkFromView(SPWeb web, SPView view)
{
SPLimitedWebPartManager limitedWebPartManager = null;
XsltListViewWebPart providerWP = null;
try {
limitedWebPartManager = web.GetLimitedWebPartManager(view.Url, PersonalizationScope.Shared);
providerWP = (from Microsoft.SharePoint.WebPartPages.WebPart webPart in limitedWebPartManager.WebParts where webPart is XsltListViewWebPart select webPart).First() as XsltListViewWebPart;
logger.Trace("jsLink for" + view.Title + " got");
return providerWP.JSLink;
}
catch (Exception ex) {
logger.Error("jsLink " + view.Title + " not got! With error: ", ex.Message);
return "";
}
finally {
if (limitedWebPartManager != null) {
if (limitedWebPartManager.Web != null) {
limitedWebPartManager.Web.Dispose();
}
limitedWebPartManager.Dispose();
}
providerWP.Dispose();
}
}
示例9: SetUpDocumentWorkspace
//.........这里部分代码省略.........
string presenter = string.Empty;
if (eventProperties.ListItem["Presenter"] != null)
presenter = eventProperties.ListItem["Presenter"].ToString();
AddAgendaToMeetingWorkspace(boardWeb, meetingWorkspaceURL, eventProperties.ListItem.Title, spUser, eventProperties.ListItemId, presenter, agendaOrder);
}
//Add the item to the Future Agenda List (Look Ahead list in EMIS)
SPList lookAheadListInEMIS = eventProperties.Web.Lists[lookAheadListNameInEmis];
SPListItem futureAgendaItem = lookAheadListInEMIS.AddItem();
futureAgendaItem["Board Agenda"] = eventProperties.ListItem.Title;
futureAgendaItem["Board Meeting"] = meetingTitle;
futureAgendaItem["Meeting Date"] = meetingDate;
futureAgendaItem["AgendaID"] = eventProperties.ListItemId;
futureAgendaItem["ResponsiblePerson"] = spUser.Name;
futureAgendaItem["Office"] = eventProperties.ListItem["AGM Office"].ToString();
futureAgendaItem["Committee Meeting ID"] = eventProperties.ListItem["CommitteeMeeting"].ToString();
futureAgendaItem["Agenda Status"] = "Agenda Created";
futureAgendaItem["DocumentWorkspace"] = eventProperties.ListItem["DocumentWorkspace"].ToString();
futureAgendaItem.Update();
//Add the Link Item
SPListItem newMeetingLink = documentWorkspace.Lists["Links"].Items.Add();
newMeetingLink["URL"] = meetingWorkspaceURL;
newMeetingLink.Update();
SPWorkflowTemplate template = null;
//Now associate the workflow
//Activate all the necessary features on the site
documentWorkspace.Features.Add(new Guid("24512e0e-7b03-466e-9209-38b39a51c581")); // Board Agenda Workflow
foreach (SPWorkflowTemplate localwfTemplate in documentWorkspace.WorkflowTemplates)
{
if (localwfTemplate.Name == "BoardAgendaWorkflow") //TODO: This should come from configuration.
{
template = localwfTemplate;
}
}
if (template == null) // If the template was not in the document workspace, then check root web for it.
{
foreach (SPWorkflowTemplate wfTemplate in rootWeb.RootWeb.WorkflowTemplates)
{
if (wfTemplate.Name == "BoardAgendaWorkflow") //TODO: This should come from configuration.
{
template = wfTemplate;
}
}
}
//Delete the default task list that is created
SPList defaultTaskList = documentWorkspace.Lists["Tasks"];
documentWorkspace.Lists.Delete(defaultTaskList.ID);
//After a Document Set is created, Create two lists in this Document Set
//1. Workflow History
//2. Agenda WF Tasks
Guid taskListID = documentWorkspace.Lists.Add("Agenda Tasks", "This task list holds all the tasks associated with the Agenda Workflow", rootWeb.RootWeb.ListTemplates["Agenda Tasks"]); //TODO: Get this from configuration.
//Guid taskListID = documentWorkspace.Lists.Add("Tasks", "", SPListTemplateType.Tasks);
Guid historyListID = documentWorkspace.Lists.Add("Workflow History", "History list used by the Agenda Workflow", SPListTemplateType.WorkflowHistory);
SPWorkflowAssociation workflowAssociation = SPWorkflowAssociation.CreateListAssociation(template, "Board Agenda Workflow", documentWorkspace.Lists[taskListID], documentWorkspace.Lists[historyListID]);
workflowAssociation.AllowManual = true;
workflowAssociation.AutoStartCreate = false;
workflowAssociation.AutoStartChange = false;
documentSet.ParentList.WorkflowAssociations.Add(workflowAssociation);
SPList AgendaList = documentWorkspace.Lists[taskListID];
AgendaList.EnableAssignToEmail = true;
AgendaList.Update();
SPList taskList = documentWorkspace.Lists[taskListID];
taskList.OnQuickLaunch = true;
taskList.Update();
SPList historyList = documentWorkspace.Lists[historyListID];
historyList.OnQuickLaunch = false;
historyList.Update();
//Remove the Announcements Webpart.
SPLimitedWebPartManager webPartManager = documentWorkspace.GetLimitedWebPartManager("Default.aspx", System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
for (int k = 0; k < webPartManager.WebParts.Count; k++)
{
//get reference to webpart
WebPart wp = webPartManager.WebParts[k] as WebPart;
//check webpart Title to find webpart which is to be removed
if ((wp.Title == "Announcements") || (wp.Title == "Members"))
{
//delete webpart
webPartManager.DeleteWebPart(webPartManager.WebParts[k]);
//update spWeb object
documentWorkspace.Update();
}
}
documentWorkspace.AllowUnsafeUpdates = false;
}
示例10: SetUpDocumentWorkspace
//.........这里部分代码省略.........
Guid historyListID = documentWorkspace.Lists.Add("Workflow History", "History list used by the Agenda Workflow", SPListTemplateType.WorkflowHistory);
Guid keyPeopleListID = documentWorkspace.Lists.Add("Key People", "List of key people associated with this Agenda", rootWeb.RootWeb.ListTemplates["KeyPeopleDefinition"]);
SPWorkflowAssociation workflowAssociation = SPWorkflowAssociation.CreateListAssociation(template, "Board Agenda Workflow", documentWorkspace.Lists[taskListID], documentWorkspace.Lists[historyListID]);
workflowAssociation.AllowManual = true;
workflowAssociation.AutoStartCreate = false;
workflowAssociation.AutoStartChange = false;
documentSet.ParentList.WorkflowAssociations.Add(workflowAssociation);
SPWorkflowAssociation wfAssociationForNotifyCoordinators = SPWorkflowAssociation.CreateListAssociation(notifyCoordinatorsWFTemplate, "Notify Coordinators Workflow", documentWorkspace.Lists[taskListID], documentWorkspace.Lists[historyListID]);
wfAssociationForNotifyCoordinators.AllowManual = true;
wfAssociationForNotifyCoordinators.AutoStartCreate = false;
wfAssociationForNotifyCoordinators.AutoStartChange = false;
documentSet.ParentList.WorkflowAssociations.Add(wfAssociationForNotifyCoordinators);
SPWorkflowAssociation wfAssociationForReviewContent = SPWorkflowAssociation.CreateListAssociation(reviewContentWFTemplate, "Review Content Workflow", documentWorkspace.Lists[taskListID], documentWorkspace.Lists[historyListID]);
wfAssociationForReviewContent.AllowManual = true;
wfAssociationForReviewContent.AutoStartCreate = false;
wfAssociationForReviewContent.AutoStartChange = false;
documentSet.ParentList.WorkflowAssociations.Add(wfAssociationForReviewContent);
SPWorkflowAssociation wfAssociationForDigitalSignatures = SPWorkflowAssociation.CreateListAssociation(digitalSignaturesWFTemplate, "Digital Signatures", documentWorkspace.Lists[taskListID], documentWorkspace.Lists[historyListID]);
wfAssociationForDigitalSignatures.AllowManual = true;
wfAssociationForDigitalSignatures.AutoStartCreate = false;
wfAssociationForDigitalSignatures.AutoStartChange = false;
documentSet.ParentList.WorkflowAssociations.Add(wfAssociationForDigitalSignatures);
SPList AgendaList = documentWorkspace.Lists[taskListID];
AgendaList.EnableAssignToEmail = true;
AgendaList.Update();
SPList taskList = documentWorkspace.Lists[taskListID];
taskList.OnQuickLaunch = true;
taskList.Update();
SPView defaultView = taskList.Views["All Tasks"];
SPViewFieldCollection viewFields = defaultView.ViewFields;
viewFields.Add(taskList.Fields["Comments"]);
viewFields.Delete(taskList.Fields["Predecessors"]);
viewFields.Delete(taskList.Fields["Description"]);
defaultView.Update();
SPList historyList = documentWorkspace.Lists[historyListID];
historyList.OnQuickLaunch = false;
historyList.Update();
SPList keyPeopleList = documentWorkspace.Lists[keyPeopleListID];
keyPeopleList.OnQuickLaunch = true;
keyPeopleList.Update();
SPList defaultCalendarList = documentWorkspace.Lists["Calendar"];
defaultCalendarList.OnQuickLaunch = false;
defaultCalendarList.Update();
AddKeyPeopleToAgenda(rootWeb, documentWorkspace, keyPeopleListID, masterKeyPeopleListName, agendaType, eventProperties.ListItem["AGM Office"].ToString());
string assemblyName = "PaperlessBoard EventHandlers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=072ce623fbaeb261";
keyPeopleList.EventReceivers.Add(SPEventReceiverType.ItemAdded, assemblyName, "PaperlessBoard_EventHandlers.KeyPeopleAddedEventReceiver.KeyPeopleAddedEventReceiver");
keyPeopleList.EventReceivers.Add(SPEventReceiverType.ItemDeleted, assemblyName, "PaperlessBoard_EventHandlers.KeyPeopleAddedEventReceiver.KeyPeopleAddedEventReceiver");
keyPeopleList.EventReceivers.Add(SPEventReceiverType.ItemUpdated, assemblyName, "PaperlessBoard_EventHandlers.KeyPeopleAddedEventReceiver.KeyPeopleAddedEventReceiver");
//Remove the Announcements Webpart.
SPLimitedWebPartManager webPartManager = documentWorkspace.GetLimitedWebPartManager("Default.aspx", System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
for (int k = 0; k < webPartManager.WebParts.Count; k++)
{
//get reference to webpart
WebPart wp = webPartManager.WebParts[k] as WebPart;
//check webpart Title to find webpart which is to be removed
if ((wp.Title == "Announcements") || (wp.Title == "Members"))
{
//delete webpart
webPartManager.DeleteWebPart(webPartManager.WebParts[k]);
//update spWeb object
documentWorkspace.Update();
}
}
AddWebPartsToWelcomePage(documentWorkspace, documentSet.WelcomePageUrl);
try
{
CleanUpQuickLaunch(documentWorkspace);
}
catch (Exception ex)
{
Microsoft.Office.Server.Diagnostics.PortalLog.LogString("Exception – {0} – {1} – {2}", "Error in Agenda Reciever while cleaning up quick launch.", ex.Message, ex.StackTrace);
}
documentWorkspace.AllowUnsafeUpdates = false;
}
示例11: AddWebPartsToWelcomePage
private void AddWebPartsToWelcomePage(SPWeb documentWorkspace, string welcomePageURL)
{
SPLimitedWebPartManager webPartManager = documentWorkspace.GetLimitedWebPartManager(welcomePageURL, System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
string SiteURL = documentWorkspace.Site.RootWeb.Url;
// Workflow Dashboard Web Part
SilverlightWebPart swpWFDashboard = new SilverlightWebPart();
swpWFDashboard.Url = string.Format(@"{0}/{1}/WorkflowDashboard.xap", SiteURL, "Apps") ;
swpWFDashboard.Height = new Unit("200px");
swpWFDashboard.Title = "Workflow Dashboard";
swpWFDashboard.ChromeType = System.Web.UI.WebControls.WebParts.PartChromeType.TitleOnly;
webPartManager.AddWebPart(swpWFDashboard, "Zone 2", 0);
// Key Events Web part
SilverlightWebPart swpKeyEvents = new SilverlightWebPart();
swpKeyEvents.Url = string.Format(@"{0}/{1}/PaperlessBoardSLWebparts.xap", SiteURL, "Apps") ;
swpKeyEvents.Title = "Key Events";
swpKeyEvents.ChromeType = System.Web.UI.WebControls.WebParts.PartChromeType.TitleOnly;
webPartManager.AddWebPart(swpKeyEvents, "Zone 2", 1);
// Key People Web Part
SilverlightWebPart swpActiveTasks = new SilverlightWebPart();
swpActiveTasks.Url = string.Format(@"{0}/{1}/ActiveTasksForWorkspace.xap", SiteURL, "Apps");
swpActiveTasks.Title = "Active Tasks";
swpActiveTasks.ChromeType = System.Web.UI.WebControls.WebParts.PartChromeType.TitleOnly;
webPartManager.AddWebPart(swpActiveTasks, "Zone 2", 2);
// Key People Web Part
SilverlightWebPart swpKeyPeople = new SilverlightWebPart();
swpKeyPeople.Url = string.Format(@"{0}/{1}/PBSilverlightKeyPeopleInAgendaWP.xap", SiteURL, "Apps") ;
swpKeyPeople.Title = "Key People";
swpKeyPeople.ChromeType = System.Web.UI.WebControls.WebParts.PartChromeType.TitleOnly;
swpKeyPeople.Height = new Unit("300px");
webPartManager.AddWebPart(swpKeyPeople, "Zone 2", 3);
documentWorkspace.Update();
}
示例12: GetLatestWebPartIndex
public static int GetLatestWebPartIndex(SPWeb web, string pageUrl, string zoneId)
{
int idx = 0;
try
{
string fullPageUrl = string.Format("{0}/{1}", web.Url.TrimEnd('/'), pageUrl.TrimStart('/'));
SPLimitedWebPartManager mgr = web.GetLimitedWebPartManager(
fullPageUrl,
System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
foreach (System.Web.UI.WebControls.WebParts.WebPart wp in mgr.WebParts)
{
if (string.IsNullOrEmpty(zoneId) || (!string.IsNullOrEmpty(zoneId) && mgr.GetZoneID(wp) == zoneId))
{
if (idx < wp.ZoneIndex) idx = wp.ZoneIndex;
}
}
}
catch (Exception) { }
return idx;
}
示例13: HideXsltListViewWebParts
public static void HideXsltListViewWebParts(SPWeb web, string pageUrl)
{
try
{
string fullPageUrl = string.Format("{0}/{1}", web.Url.TrimEnd('/'), pageUrl.TrimStart('/'));
SPLimitedWebPartManager mgr = web.GetLimitedWebPartManager(
fullPageUrl,
System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
foreach (System.Web.UI.WebControls.WebParts.WebPart wp in mgr.WebParts)
{
if (wp is SP.XsltListViewWebPart)
{
wp.Hidden = true;
mgr.SaveChanges(wp);
}
}
}
catch(Exception){}
}
示例14: MoveWebPart
public static void MoveWebPart(SPWeb web, string pageUrl, string webPartName, string zoneID, int zoneIndex)
{
try
{
string fullPageUrl = string.Format("{0}/{1}", web.Url.TrimEnd('/'), pageUrl.TrimStart('/'));
SPLimitedWebPartManager mgr = web.GetLimitedWebPartManager(
fullPageUrl,
System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
foreach (System.Web.UI.WebControls.WebParts.WebPart wp in mgr.WebParts)
{
if (wp.Title.Equals(webPartName.Replace(".webpart", "")))
{
mgr.MoveWebPart(wp, zoneID, zoneIndex);
mgr.SaveChanges(wp);
break;
}
}
}
catch (Exception) { }
}
示例15: ProvisionWebpart
public static void ProvisionWebpart(SPWeb web, WebpartPageDefinitionCollection collection)
{
foreach (var item in collection)
{
try
{
string pageUrl = item.PageUrl;
if (!string.IsNullOrEmpty(item.RootPath) && !string.IsNullOrEmpty(item.FileName))
{
if (item.RootPath.EndsWith(".aspx"))
{
item.PageUrl = item.RootPath;
pageUrl = item.RootPath;
}
else
{
pageUrl = string.Format("{0}/{1}", item.RootPath.TrimEnd('/'), SPEncode.UrlEncode(item.FileName.TrimStart('/')));
item.PageUrl = pageUrl;
}
}
if (!IsAbsoluteUrl(pageUrl))
{
pageUrl = string.Format("{0}/{1}", web.Url.TrimEnd('/'), pageUrl.TrimStart('/'));
}
web.EnsureWebpartPage(item.PageUrl, item.Title, item.Overwrite);
using (SPLimitedWebPartManager webPartManager = web.GetLimitedWebPartManager(
pageUrl, System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared))
{
foreach (var wp in item.Webparts)
{
try
{
using (var concerateWP = wp.CreateWebPart(web, webPartManager))
{
if (concerateWP == null) continue;
try
{
if (!wp.AllowDuplicate && webPartManager.WebParts.Cast<System.Web.UI.WebControls.WebParts.WebPart>().Any(p => p.Title == concerateWP.Title))
{
continue;
}
}
catch (Exception)
{
//throw;
}
webPartManager.AddWebPart(concerateWP, wp.ZoneId, wp.Index ==0 ?webPartManager.WebParts.Count+1: wp.Index);
CreateDefaultWebPart(web, webPartManager, wp, concerateWP);
}
}
catch (Exception ex)
{
}
}
}
}
catch (Exception ex)
{
}
}
}