1
기존 XlstListviewwebpart에 새 항목 추가 링크를 표시하려고합니다. 그러나 아래 코드는 작동하지 않습니다. http://suryapulipati.blogspot.be/2011/08/sharepoint-2010-show-add-new-item-or.htmlShow 프로그래밍 방식으로 XsltListViewWebPart에 새 항목 추가
을하지만 항상 내가이 좋아했다
private void ShowAddOrganisationLinkOnHomePage(string webUrl)
{
Logger.LogDebug("NLSponsoringSiteConfigSponsoringCentralEventReceiver", "ConfigureOrganisationDashboard(SPWeb currentWeb)", "BEGIN");
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPFile pageOrganisation = null;
using (SPWeb oHomeWeb = new SPSite(webUrl).OpenWeb())
{
try
{
pageOrganisation = oHomeWeb.GetFile("default.aspx");
pageOrganisation.CheckOut();
string idWebPartRootOrganisation = "ID_RootOrganisation";
oHomeWeb.AllowUnsafeUpdates = true;
using (SPLimitedWebPartManager mgrPageManager = pageOrganisation.GetLimitedWebPartManager(PersonalizationScope.Shared))
{
SPList organisations = oHomeWeb.GetSafeListByName(SponsoringCommon.Constants.LISTNAMES_ORGANISATIONS2);
XsltListViewWebPart lvwpOrganisation = mgrPageManager.WebParts[idWebPartRootOrganisation] as XsltListViewWebPart;
SPView oCustomView = organisations.Views[SponsoringCommon.Constants.VIEWS_ORGANISATION_DASHBOARD_NAME];
PropertyInfo nodeProp = oCustomView.GetType().GetProperty("Node", BindingFlags.NonPublic | BindingFlags.Instance);
XmlNode node = nodeProp.GetValue(oCustomView, null) as XmlNode;
XmlNode toolbarNode = node.SelectSingleNode("Toolbar");
if (toolbarNode != null)
{
if (!toolbarNode.Attributes["Type"].Value.Equals("Freeform"))
{
toolbarNode.Attributes["Type"].Value = "Freeform";
}
}
oCustomView.Update();
mgrPageManager.SaveChanges(lvwpOrganisation);
}
}
catch (Exception)
{
oHomeWeb.AllowUnsafeUpdates = false;
if (pageOrganisation != null) pageOrganisation.UndoCheckOut();
throw;
}
finally
{
pageOrganisation.CheckIn(string.Empty);
oHomeWeb.AllowUnsafeUpdates = false;
}
}
});
}
이 SP2013 정말 잘 작동합니다! 나는 툴바를 변경하기 위해 사용자 webpart 관리자에게하지 않았다. 단지 SetToolBarType() 메소드가 트릭을 수행했다. – SAV