// <Snippet3> protected override Style CreateEditorPartChromeStyle(EditorPart editorPart, PartChromeType chromeType) { Style editorStyle = base.CreateEditorPartChromeStyle(editorPart, chromeType); editorStyle.BackColor = Color.Bisque; return(editorStyle); }
protected virtual Style CreateEditorPartChromeStyle(EditorPart editorPart, PartChromeType chromeType) { if (editorPart == null) { throw new ArgumentNullException("editorPart"); } if ((chromeType < PartChromeType.Default) || (chromeType > PartChromeType.BorderOnly)) { throw new ArgumentOutOfRangeException("chromeType"); } if ((chromeType == PartChromeType.BorderOnly) || (chromeType == PartChromeType.TitleAndBorder)) { return this.Zone.PartChromeStyle; } if (this._chromeStyleNoBorder == null) { Style style = new Style(); style.CopyFrom(this.Zone.PartChromeStyle); if (style.BorderStyle != BorderStyle.None) { style.BorderStyle = BorderStyle.None; } if (style.BorderWidth != Unit.Empty) { style.BorderWidth = Unit.Empty; } if (style.BorderColor != Color.Empty) { style.BorderColor = Color.Empty; } this._chromeStyleNoBorder = style; } return this._chromeStyleNoBorder; }
/// <devdoc> /// The effective chrome type of a part, taking into consideration the PartChromeType /// of the zone and the DisplayMode of the page. /// </devdoc> public virtual PartChromeType GetEffectiveChromeType(Part part) { if (part == null) { throw new ArgumentNullException("part"); } PartChromeType chromeType = part.ChromeType; if (chromeType == PartChromeType.Default) { PartChromeType partChromeType = PartChromeType; if (partChromeType == PartChromeType.Default) { chromeType = PartChromeType.TitleAndBorder; } else { chromeType = partChromeType; } } Debug.Assert(chromeType != PartChromeType.Default); return(chromeType); }
internal Part() { description = ""; title = ""; chrome_state = PartChromeState.Normal; chrome_type = PartChromeType.Default; }
public virtual void RenderEditorPart(HtmlTextWriter writer, EditorPart editorPart) { if (editorPart == null) { throw new ArgumentNullException("editorPart"); } PartChromeType effectiveChromeType = this.Zone.GetEffectiveChromeType(editorPart); Style style = this.CreateEditorPartChromeStyle(editorPart, effectiveChromeType); if (!style.IsEmpty) { style.AddAttributesToRender(writer, this.Zone); } writer.RenderBeginTag(HtmlTextWriterTag.Fieldset); switch (effectiveChromeType) { case PartChromeType.TitleAndBorder: case PartChromeType.TitleOnly: this.RenderTitle(writer, editorPart); break; } if (editorPart.ChromeState != PartChromeState.Minimized) { Style partStyle = this.Zone.PartStyle; if (!partStyle.IsEmpty) { partStyle.AddAttributesToRender(writer, this.Zone); } writer.RenderBeginTag(HtmlTextWriterTag.Div); this.RenderPartContents(writer, editorPart); writer.RenderEndTag(); } writer.RenderEndTag(); }
protected virtual Style CreateEditorPartChromeStyle(EditorPart editorPart, PartChromeType chromeType) { if (editorPart == null) { throw new ArgumentNullException("editorPart"); } if ((chromeType < PartChromeType.Default) || (chromeType > PartChromeType.BorderOnly)) { throw new ArgumentOutOfRangeException("chromeType"); } if ((chromeType == PartChromeType.BorderOnly) || (chromeType == PartChromeType.TitleAndBorder)) { return(this.Zone.PartChromeStyle); } if (this._chromeStyleNoBorder == null) { Style style = new Style(); style.CopyFrom(this.Zone.PartChromeStyle); if (style.BorderStyle != BorderStyle.None) { style.BorderStyle = BorderStyle.None; } if (style.BorderWidth != Unit.Empty) { style.BorderWidth = Unit.Empty; } if (style.BorderColor != Color.Empty) { style.BorderColor = Color.Empty; } this._chromeStyleNoBorder = style; } return(this._chromeStyleNoBorder); }
internal Part () { description = ""; title = ""; chrome_state = PartChromeState.Normal; chrome_type = PartChromeType.Default; }
public static void AddCustomContentQueryWebPart(SPWeb web, string pageUrl, string zoneId, int zoneIndex, string title, PartChromeState chromState, PartChromeType chromeType) { NCNewssitePatch1CustomContentQueryWebPart customContent = new NCNewssitePatch1CustomContentQueryWebPart(); customContent.ZoneID = zoneId; customContent.Title = title; customContent.ChromeState = chromState; customContent.ChromeType = chromeType; AddWebPart(web, customContent, pageUrl, zoneIndex); }
public static void AddCEWP(SPWeb web, string pageUrl, string zoneId,int zoneIndex, string title, PartChromeState chromState, PartChromeType chromeType) { ContentEditorWebPart contentEditor = new ContentEditorWebPart(); contentEditor.ZoneID = zoneId; contentEditor.Title = title; contentEditor.ChromeState = chromState; contentEditor.ChromeType = chromeType; AddWebPart(web, contentEditor, pageUrl, zoneIndex); }
protected override Style CreateWebPartChromeStyle(WebPart part, PartChromeType chromeType) { Style finalStyle = new Style(); finalStyle.CopyFrom(base.CreateWebPartChromeStyle(part, chromeType)); finalStyle.Font.Name = "Verdana"; return(finalStyle); }
public virtual void RenderEditorPart(HtmlTextWriter writer, EditorPart editorPart) { if (editorPart == null) { throw new ArgumentNullException("editorPart"); } PartChromeType chromeType = Zone.GetEffectiveChromeType(editorPart); Style partChromeStyle = CreateEditorPartChromeStyle(editorPart, chromeType); // Apply ChromeStyle to the Fieldset if (!partChromeStyle.IsEmpty) { partChromeStyle.AddAttributesToRender(writer, Zone); } writer.RenderBeginTag(HtmlTextWriterTag.Fieldset); // Use ChromeType to determine whether to render the legend if (chromeType == PartChromeType.TitleAndBorder || chromeType == PartChromeType.TitleOnly) { RenderTitle(writer, editorPart); } if (editorPart.ChromeState != PartChromeState.Minimized) { // Apply PartStyle to a <div> around the part rendering Style partStyle = Zone.PartStyle; if (!partStyle.IsEmpty) { partStyle.AddAttributesToRender(writer, Zone); } // We want to have 5 pixels of spacing aroung the EditorPart contents. There are // 3 ways to accomplish this: // 1. <fieldset style="padding:5px"> - This is bad because it adds 5px of space above // the legend. It also makes the fieldset too wide. // 2. <fieldset><div style="padding:5px"> - This is bad because the PartStyle-BackColor // will now span the whole width of the legend. For consistency with WebPartChrome, // we want the PartChromeStyle-BackColor to show in the 5px of space around the contents. // 3. <fieldset><div style="margin:5px"> - This is the best option. // // For now, I don't think we should render a margin here. People writing custom // EditorParts can add a margin to their contents if they want it. This is not the // same as the WebPartChrome case, since for WebParts we allow people to use ServerControls, // that will likely not have a margin. (VSWhidbey 324397) // writer.AddStyleAttribute(HtmlTextWriterStyle.Margin, "5px"); writer.RenderBeginTag(HtmlTextWriterTag.Div); RenderPartContents(writer, editorPart); writer.RenderEndTag(); // Div } writer.RenderEndTag(); // Fieldset }
public virtual void RenderCatalogPart(HtmlTextWriter writer, CatalogPart catalogPart) { if (catalogPart == null) { throw new ArgumentNullException("catalogPart"); } PartChromeType effectiveChromeType = this.Zone.GetEffectiveChromeType(catalogPart); Style style = this.CreateCatalogPartChromeStyle(catalogPart, effectiveChromeType); if (!style.IsEmpty) { style.AddAttributesToRender(writer, this.Zone); } writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0"); writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "2"); writer.AddAttribute(HtmlTextWriterAttribute.Border, "0"); writer.AddStyleAttribute(HtmlTextWriterStyle.Width, "100%"); writer.RenderBeginTag(HtmlTextWriterTag.Table); switch (effectiveChromeType) { case PartChromeType.TitleOnly: case PartChromeType.TitleAndBorder: { writer.RenderBeginTag(HtmlTextWriterTag.Tr); Style partTitleStyle = this.Zone.PartTitleStyle; if (!partTitleStyle.IsEmpty) { partTitleStyle.AddAttributesToRender(writer, this.Zone); } writer.RenderBeginTag(HtmlTextWriterTag.Td); this.RenderTitle(writer, catalogPart); writer.RenderEndTag(); writer.RenderEndTag(); break; } } if (catalogPart.ChromeState != PartChromeState.Minimized) { writer.RenderBeginTag(HtmlTextWriterTag.Tr); Style partStyle = this.Zone.PartStyle; if (!partStyle.IsEmpty) { partStyle.AddAttributesToRender(writer, this.Zone); } writer.RenderBeginTag(HtmlTextWriterTag.Td); this.RenderPartContents(writer, catalogPart); this.RenderItems(writer, catalogPart); writer.RenderEndTag(); writer.RenderEndTag(); } writer.RenderEndTag(); }
protected virtual Style CreateEditorPartChromeStyle(EditorPart editorPart, PartChromeType chromeType) { if (editorPart == null) { throw new ArgumentNullException("editorPart"); } if ((chromeType < PartChromeType.Default) || (chromeType > PartChromeType.BorderOnly)) { throw new ArgumentOutOfRangeException("chromeType"); } // PERF: Cache these, since they are needed for every EditorPart in the zone. if (chromeType == PartChromeType.BorderOnly || chromeType == PartChromeType.TitleAndBorder) { // We don't want to set any border styles for ChromeType of TitleAndBorder or BorderOnly, // since the FrameSet has a default border, and it will use XP themes as long as no border styles // are set. // PERF: Just return the Zone.PartChromeStyle directly without making a copy return(Zone.PartChromeStyle); } else { if (_chromeStyleNoBorder == null) { Style style = new Style(); // create copy of PartChromeStyle so we can modify it style.CopyFrom(Zone.PartChromeStyle); if (style.BorderStyle != BorderStyle.None) { style.BorderStyle = BorderStyle.None; } if (style.BorderWidth != Unit.Empty) { style.BorderWidth = Unit.Empty; } if (style.BorderColor != Color.Empty) { style.BorderColor = Color.Empty; } _chromeStyleNoBorder = style; } return(_chromeStyleNoBorder); } }
protected virtual Style CreateCatalogPartChromeStyle(CatalogPart catalogPart, PartChromeType chromeType) { if (catalogPart == null) { throw new ArgumentNullException("catalogPart"); } if ((chromeType < PartChromeType.Default) || (chromeType > PartChromeType.BorderOnly)) { throw new ArgumentOutOfRangeException("chromeType"); } if (chromeType == PartChromeType.BorderOnly || chromeType == PartChromeType.TitleAndBorder) { if (_chromeStyleWithBorder == null) { Style style = new Style(); style.CopyFrom(Zone.PartChromeStyle); if (style.BorderStyle == BorderStyle.NotSet) { style.BorderStyle = BorderStyle.Solid; } if (style.BorderWidth == Unit.Empty) { style.BorderWidth = Unit.Pixel(1); } if (style.BorderColor == Color.Empty) { style.BorderColor = Color.Black; } _chromeStyleWithBorder = style; } return _chromeStyleWithBorder; } else { if (_chromeStyleNoBorder == null) { Style style = new Style(); style.CopyFrom(Zone.PartChromeStyle); if (style.BorderStyle != BorderStyle.NotSet) { style.BorderStyle = BorderStyle.NotSet; } if (style.BorderWidth != Unit.Empty) { style.BorderWidth = Unit.Empty; } if (style.BorderColor != Color.Empty) { style.BorderColor = Color.Empty; } _chromeStyleNoBorder = style; } return _chromeStyleNoBorder; } }
protected virtual Style CreateWebPartChromeStyle(WebPart webPart, PartChromeType chromeType) { if (webPart == null) { throw new ArgumentNullException("webPart"); } if ((chromeType < PartChromeType.Default) || (chromeType > PartChromeType.BorderOnly)) { throw new ArgumentOutOfRangeException("chromeType"); } // PERF: Cache these, since they are needed for every WebPart in the zone, and only vary // if one of the WebParts is selected Style webPartChromeStyle; if (chromeType == PartChromeType.BorderOnly || chromeType == PartChromeType.TitleAndBorder) { if (_chromeStyleWithBorder == null) { _chromeStyleWithBorder = CreateChromeStyleWithBorder(Zone.PartChromeStyle); } webPartChromeStyle = _chromeStyleWithBorder; } else { if (_chromeStyleNoBorder == null) { _chromeStyleNoBorder = CreateChromeStyleNoBorder(Zone.PartChromeStyle); } webPartChromeStyle = _chromeStyleNoBorder; } // add SelectedPartChromeStyle if (WebPartManager != null && webPart == WebPartManager.SelectedWebPart) { Style style = new Style(); style.CopyFrom(webPartChromeStyle); style.CopyFrom(Zone.SelectedPartChromeStyle); return(style); } else { return(webPartChromeStyle); } }
protected virtual Style CreateEditorPartChromeStyle(EditorPart editorPart, PartChromeType chromeType) { if (editorPart == null) { throw new ArgumentNullException("editorPart"); } if ((chromeType < PartChromeType.Default) || (chromeType > PartChromeType.BorderOnly)) { throw new ArgumentOutOfRangeException("chromeType"); } // PERF: Cache these, since they are needed for every EditorPart in the zone. if (chromeType == PartChromeType.BorderOnly || chromeType == PartChromeType.TitleAndBorder) { // We don't want to set any border styles for ChromeType of TitleAndBorder or BorderOnly, // since the FrameSet has a default border, and it will use XP themes as long as no border styles // are set. // PERF: Just return the Zone.PartChromeStyle directly without making a copy return Zone.PartChromeStyle; } else { if (_chromeStyleNoBorder == null) { Style style = new Style(); // create copy of PartChromeStyle so we can modify it style.CopyFrom(Zone.PartChromeStyle); if (style.BorderStyle != BorderStyle.None) { style.BorderStyle = BorderStyle.None; } if (style.BorderWidth != Unit.Empty) { style.BorderWidth = Unit.Empty; } if (style.BorderColor != Color.Empty) { style.BorderColor = Color.Empty; } _chromeStyleNoBorder = style; } return _chromeStyleNoBorder; } }
protected virtual Style CreateWebPartChromeStyle(WebPart webPart, PartChromeType chromeType) { Style style; if (webPart == null) { throw new ArgumentNullException("webPart"); } if ((chromeType < PartChromeType.Default) || (chromeType > PartChromeType.BorderOnly)) { throw new ArgumentOutOfRangeException("chromeType"); } if ((chromeType == PartChromeType.BorderOnly) || (chromeType == PartChromeType.TitleAndBorder)) { if (this._chromeStyleWithBorder == null) { this._chromeStyleWithBorder = this.CreateChromeStyleWithBorder(this.Zone.PartChromeStyle); } style = this._chromeStyleWithBorder; } else { if (this._chromeStyleNoBorder == null) { this._chromeStyleNoBorder = this.CreateChromeStyleNoBorder(this.Zone.PartChromeStyle); } style = this._chromeStyleNoBorder; } if ((this.WebPartManager != null) && (webPart == this.WebPartManager.SelectedWebPart)) { Style style2 = new Style(); style2.CopyFrom(style); style2.CopyFrom(this.Zone.SelectedPartChromeStyle); return(style2); } return(style); }
/// <summary> /// Adds the web part. /// </summary> /// <param name="file">The page.</param> /// <param name="webPartXml">The web part XML file.</param> /// <param name="webPartTitle">The web part title.</param> /// <param name="zone">The zone.</param> /// <param name="zoneId">The zone id.</param> /// <param name="deleteWebPart">if set to <c>true</c> [delete web part].</param> /// <param name="customReplaceText">The custom replace text.</param> /// <param name="chromeType">Type of the chrome.</param> /// <param name="publish">if set to <c>true</c> [publish].</param> /// <returns></returns> public WebPart AddWebPart(SPFile file, string webPartXml, string assembly, string typeName, string webPartTitle, string zone, int zoneId, bool deleteWebPart, Hashtable customReplaceText, PartChromeType chromeType, bool publish) { bool cleanupContext = false; bool checkBackIn = false; if (file.InDocumentLibrary) { if (!Utilities.IsCheckedOut(file.Item) || !Utilities.IsCheckedOutByCurrentUser(file.Item)) { checkBackIn = true; file.CheckOut(); } // If it's checked out by another user then this will throw an informative exception so let it do so. } if (HttpContext.Current == null) { cleanupContext = true; HttpRequest httpRequest = new HttpRequest("", file.Item.ParentList.ParentWeb.Url, ""); HttpContext.Current = new HttpContext(httpRequest, new HttpResponse(new StringWriter())); SPControl.SetContextWeb(HttpContext.Current, file.Item.ParentList.ParentWeb); } string url = file.Item.ParentList.ParentWeb.Site.MakeFullUrl(file.ServerRelativeUrl); using (SPLimitedWebPartManager manager = file.Item.ParentList.ParentWeb.GetLimitedWebPartManager(url, PersonalizationScope.Shared)) { try { WebPart wp; if (!string.IsNullOrEmpty(webPartXml)) { wp = AddWebPart(manager, file, webPartXml, customReplaceText); } else { wp = AddWebPart(assembly, typeName); } if (!string.IsNullOrEmpty(webPartTitle)) { wp.Title = webPartTitle; } webPartTitle = wp.Title; wp.ChromeType = chromeType; // Delete existing web part with same title so that we only have the latest version on the page foreach (WebPart wpTemp in manager.WebParts) { try { if (wpTemp.Title == wp.Title) { if (deleteWebPart) { manager.DeleteWebPart(wpTemp); break; } else { continue; } } } finally { wpTemp.Dispose(); } } try { manager.AddWebPart(wp, zone, zoneId); } catch (Exception) { System.Net.ServicePointManager.ServerCertificateValidationCallback += delegate { return(true); }; // We've not already added the web part so use the web service to do this. using (WebPartPagesWebService.WebPartPagesWebService svc = new WebPartPagesWebService.WebPartPagesWebService()) { // We failed adding via the OM so try the web service as a fall back. svc.Url = manager.Web.Url + "/_vti_bin/WebPartPages.asmx"; svc.Credentials = System.Net.CredentialCache.DefaultCredentials; try { // Add the web part to the web service. We use a web service because many // web parts require the SPContext.Current variables to be set which are // not set when run from a command line. StringBuilder sb = new StringBuilder(); XmlTextWriter xmlWriter = new XmlTextWriter(new StringWriter(sb)); xmlWriter.Formatting = Formatting.Indented; manager.ExportWebPart(wp, xmlWriter); xmlWriter.Flush(); svc.AddWebPartToZone(url, sb.ToString(), WebPartPagesWebService.Storage.Shared, zone, zoneId); } catch (System.Web.Services.Protocols.SoapException ex) { throw new Exception(ex.Detail.OuterXml); } } } return(wp); } finally { if (cleanupContext) { HttpContext.Current = null; } if (manager != null) { manager.Web.Dispose(); manager.Dispose(); } if (file.InDocumentLibrary && Utilities.IsCheckedOut(file.Item) && (checkBackIn || publish)) { file.CheckIn("Checking in changes to page due to new web part being added: " + webPartTitle); } if (publish && file.InDocumentLibrary && file.Item.ParentList.EnableMinorVersions) { try { file.Publish("Publishing changes to page due to new web part being added: " + webPartTitle); if (file.Item.ModerationInformation != null) { file.Approve("Approving changes to page due to new web part being added: " + webPartTitle); } } catch (Exception ex) { WriteWarning("Unable to publish or approve file: " + ex.Message); } } } } }
public static void AddWebPart(SPLimitedWebPartManager webPartManager, System.Web.UI.WebControls.WebParts.WebPart webPart, string zone, int zoneIndex, PartChromeType chromeType, string accesskey) { webPartManager.RequireNotNull("webPartManager"); webPart.RequireNotNull("webPart"); zone.RequireNotNullOrEmpty("zone"); zoneIndex.Require(zoneIndex >= 0, "zoneIndex"); webPart.AccessKey = accesskey; webPart.ChromeType = chromeType; webPartManager.AddWebPart(webPart, zone, zoneIndex); webPartManager.SaveChanges(webPart); }
public static void CreateContentEditorWebPart(SPLimitedWebPartManager webPartManager, string Content, string zone, int zoneIndex, PartChromeType chromeType, string webPartTitle) { // validation webPartManager.RequireNotNull("webPartManager"); Content.RequireNotNullOrEmpty("Content"); zone.RequireNotNullOrEmpty("zone"); webPartTitle.RequireNotNullOrEmpty("webPartTitle"); Guid storageKey = Guid.NewGuid(); string wpId = String.Format("g_{0}", storageKey.ToString().Replace('-', '_')); XmlDocument doc = new XmlDocument(); XmlElement div = doc.CreateElement("div"); div.InnerText = Content; ContentEditorWebPart cewp = new ContentEditorWebPart { Content = div, ID = wpId, Title = webPartTitle }; cewp.ChromeType = chromeType; webPartManager.AddWebPart(cewp, zone, zoneIndex); webPartManager.SaveChanges(cewp); }
protected virtual new System.Web.UI.WebControls.Style CreateCatalogPartChromeStyle(CatalogPart catalogPart, PartChromeType chromeType) { return(default(System.Web.UI.WebControls.Style)); }
/// <summary> /// Adds a List View Web Part to the specified page. /// </summary> /// <param name="pageUrl">The page URL.</param> /// <param name="listUrl">The list URL.</param> /// <param name="title">The title.</param> /// <param name="viewTitle">Title of the view.</param> /// <param name="zoneId">The zone ID.</param> /// <param name="zoneIndex">Index within the zone.</param> /// <param name="linkTitle">if set to <c>true</c> [link title].</param> /// <param name="chromeType">Type of the chrome.</param> /// <param name="publish">if set to <c>true</c> [publish].</param> /// <returns></returns> public static Microsoft.SharePoint.WebPartPages.WebPart Add(string pageUrl, string listUrl, string title, string viewTitle, string zoneId, int zoneIndex, bool linkTitle, string jsLink, PartChromeType chromeType, bool publish) { using (SPSite site = new SPSite(pageUrl)) using (SPWeb web = site.OpenWeb()) // The url contains a filename so AllWebs[] will not work unless we want to try and parse which we don't { SPFile file = web.GetFile(pageUrl); // file.Item will throw "The object specified does not belong to a list." if the url passed // does not correspond to a file in a list. SPList list = Utilities.GetListFromViewUrl(listUrl); if (list == null) throw new ArgumentException("List not found."); SPView view = null; if (!string.IsNullOrEmpty(viewTitle)) { view = list.Views.Cast<SPView>().FirstOrDefault(v => v.Title == viewTitle); if (view == null) throw new ArgumentException("The specified view was not found."); } bool checkBackIn = false; if (file.InDocumentLibrary) { if (!Utilities.IsCheckedOut(file.Item) || !Utilities.IsCheckedOutByCurrentUser(file.Item)) { checkBackIn = true; file.CheckOut(); } // If it's checked out by another user then this will throw an informative exception so let it do so. } string displayTitle = string.Empty; Microsoft.SharePoint.WebPartPages.WebPart lvw = null; SPLimitedWebPartManager manager = null; try { manager = web.GetLimitedWebPartManager(pageUrl, PersonalizationScope.Shared); lvw = new XsltListViewWebPart(); if (list.BaseTemplate == SPListTemplateType.Events) lvw = new ListViewWebPart(); if (lvw is ListViewWebPart) { ((ListViewWebPart)lvw).ListName = list.ID.ToString("B").ToUpperInvariant(); ((ListViewWebPart)lvw).WebId = list.ParentWeb.ID; if (view != null) ((ListViewWebPart)lvw).ViewGuid = view.ID.ToString("B").ToUpperInvariant(); } else { ((XsltListViewWebPart)lvw).ListName = list.ID.ToString("B").ToUpperInvariant(); #if SP2013 if (!string.IsNullOrEmpty(jsLink)) ((XsltListViewWebPart)lvw).JSLink = jsLink; #endif ((XsltListViewWebPart)lvw).WebId = list.ParentWeb.ID; if (view != null) ((XsltListViewWebPart)lvw).ViewGuid = view.ID.ToString("B").ToUpperInvariant(); } if (linkTitle) { if (view != null) lvw.TitleUrl = view.Url; else lvw.TitleUrl = list.DefaultViewUrl; } if (!string.IsNullOrEmpty(title)) lvw.Title = title; lvw.ChromeType = chromeType; displayTitle = lvw.DisplayTitle; manager.AddWebPart(lvw, zoneId, zoneIndex); } finally { if (manager != null) { manager.Web.Dispose(); manager.Dispose(); } if (lvw != null) lvw.Dispose(); if (file.InDocumentLibrary && Utilities.IsCheckedOut(file.Item) && (checkBackIn || publish)) file.CheckIn("Checking in changes to page due to new web part being added: " + displayTitle); if (publish && file.InDocumentLibrary) { file.Publish("Publishing changes to page due to new web part being added: " + displayTitle); if (file.Item.ModerationInformation != null) { file.Approve("Approving changes to page due to new web part being added: " + displayTitle); } } } return lvw; } }
protected virtual Style CreateCatalogPartChromeStyle(CatalogPart catalogPart, PartChromeType chromeType) { if (catalogPart == null) { throw new ArgumentNullException("catalogPart"); } if ((chromeType < PartChromeType.Default) || (chromeType > PartChromeType.BorderOnly)) { throw new ArgumentOutOfRangeException("chromeType"); } if (chromeType == PartChromeType.BorderOnly || chromeType == PartChromeType.TitleAndBorder) { if (_chromeStyleWithBorder == null) { Style style = new Style(); style.CopyFrom(Zone.PartChromeStyle); if (style.BorderStyle == BorderStyle.NotSet) { style.BorderStyle = BorderStyle.Solid; } if (style.BorderWidth == Unit.Empty) { style.BorderWidth = Unit.Pixel(1); } if (style.BorderColor == Color.Empty) { style.BorderColor = Color.Black; } _chromeStyleWithBorder = style; } return(_chromeStyleWithBorder); } else { if (_chromeStyleNoBorder == null) { Style style = new Style(); style.CopyFrom(Zone.PartChromeStyle); if (style.BorderStyle != BorderStyle.NotSet) { style.BorderStyle = BorderStyle.NotSet; } if (style.BorderWidth != Unit.Empty) { style.BorderWidth = Unit.Empty; } if (style.BorderColor != Color.Empty) { style.BorderColor = Color.Empty; } _chromeStyleNoBorder = style; } return(_chromeStyleNoBorder); } }
private string GetXsltListViewWebPartXml(Guid listId, string listUrl, Guid viewId, XmlDocument viewSchema, string pageUrl, string title, string jslink, PartChromeType chromeType) { StringBuilder wp = new StringBuilder(100); wp.Append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>"); wp.Append("<webParts>"); wp.Append(" <webPart xmlns=\"http://schemas.microsoft.com/WebPart/v3\">"); wp.Append(" <metaData>"); wp.Append(" <type name=\"Microsoft.SharePoint.WebPartPages.XsltListViewWebPart, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c\" />"); wp.Append(" <importErrorMessage>Cannot import this Web Part.</importErrorMessage>"); wp.Append(" </metaData>"); wp.Append(" <data>"); wp.Append(" <properties>"); wp.Append(" <property name=\"ShowWithSampleData\" type=\"bool\">False</property>"); wp.Append(" <property name=\"Default\" type=\"string\" />"); wp.Append(" <property name=\"NoDefaultStyle\" type=\"string\" null=\"true\" />"); wp.Append(" <property name=\"CacheXslStorage\" type=\"bool\">True</property>"); wp.Append(" <property name=\"ViewContentTypeId\" type=\"string\" />"); wp.Append(" <property name=\"XmlDefinitionLink\" type=\"string\" />"); wp.Append(" <property name=\"ManualRefresh\" type=\"bool\">False</property>"); wp.Append(" <property name=\"ListUrl\" type=\"string\" />"); wp.AppendFormat(" <property name=\"ListId\" type=\"System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\">{0}</property>", listId.ToString()); if (viewId != Guid.Empty) { wp.AppendFormat(" <property name=\"ViewGuid\" type=\"System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\">{0}</property>", viewId.ToString("B").ToUpperInvariant()); } wp.AppendFormat(" <property name=\"TitleUrl\" type=\"string\">{0}</property>", listUrl); wp.Append(" <property name=\"EnableOriginalValue\" type=\"bool\">False</property>"); wp.Append(" <property name=\"Direction\" type=\"direction\">NotSet</property>"); wp.Append(" <property name=\"ServerRender\" type=\"bool\">False</property>"); wp.Append(" <property name=\"ViewFlags\" type=\"Microsoft.SharePoint.SPViewFlags, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c\">None</property>"); wp.Append(" <property name=\"AllowConnect\" type=\"bool\">True</property>"); wp.AppendFormat(" <property name=\"ListName\" type=\"string\">{0}</property>", listId.ToString("B").ToUpperInvariant()); wp.Append(" <property name=\"ListDisplayName\" type=\"string\" />"); wp.Append(" <property name=\"AllowZoneChange\" type=\"bool\">True</property>"); wp.Append(" <property name=\"ChromeState\" type=\"chromestate\">Normal</property>"); wp.Append(" <property name=\"DisableSaveAsNewViewButton\" type=\"bool\">False</property>"); wp.Append(" <property name=\"ViewFlag\" type=\"string\" />"); wp.Append(" <property name=\"DataSourceID\" type=\"string\" />"); wp.Append(" <property name=\"ExportMode\" type=\"exportmode\">All</property>"); wp.Append(" <property name=\"AutoRefresh\" type=\"bool\">False</property>"); wp.Append(" <property name=\"FireInitialRow\" type=\"bool\">True</property>"); wp.Append(" <property name=\"AllowEdit\" type=\"bool\">True</property>"); wp.Append(" <property name=\"Description\" type=\"string\" />"); wp.Append(" <property name=\"HelpMode\" type=\"helpmode\">Modeless</property>"); wp.Append(" <property name=\"BaseXsltHashKey\" type=\"string\" null=\"true\" />"); wp.Append(" <property name=\"AllowMinimize\" type=\"bool\">True</property>"); wp.Append(" <property name=\"CacheXslTimeOut\" type=\"int\">86400</property>"); wp.AppendFormat(" <property name=\"ChromeType\" type=\"chrometype\">{0}</property>", chromeType.ToString()); wp.Append(" <property name=\"Xsl\" type=\"string\" null=\"true\" />"); if (string.IsNullOrEmpty(jslink)) { wp.Append(" <property name=\"JSLink\" type=\"string\" null=\"true\" />"); } else { wp.AppendFormat(" <property name=\"JSLink\" type=\"string\">{0}</property>", jslink); } wp.Append(" <property name=\"CatalogIconImageUrl\" type=\"string\">/_layouts/15/images/itgen.png?rev=26</property>"); wp.Append(" <property name=\"SampleData\" type=\"string\" null=\"true\" />"); wp.Append(" <property name=\"UseSQLDataSourcePaging\" type=\"bool\">True</property>"); wp.Append(" <property name=\"TitleIconImageUrl\" type=\"string\" />"); wp.Append(" <property name=\"PageSize\" type=\"int\">-1</property>"); wp.Append(" <property name=\"ShowTimelineIfAvailable\" type=\"bool\">True</property>"); wp.Append(" <property name=\"Width\" type=\"string\" />"); wp.Append(" <property name=\"DataFields\" type=\"string\" />"); wp.Append(" <property name=\"Hidden\" type=\"bool\">False</property>"); wp.AppendFormat(" <property name=\"Title\" type=\"string\">{0}</property>", title); wp.Append(" <property name=\"PageType\" type=\"Microsoft.SharePoint.PAGETYPE, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c\">PAGE_NORMALVIEW</property>"); wp.Append(" <property name=\"DataSourcesString\" type=\"string\" />"); wp.Append(" <property name=\"AllowClose\" type=\"bool\">True</property>"); wp.Append(" <property name=\"InplaceSearchEnabled\" type=\"bool\">False</property>"); wp.Append(" <property name=\"WebId\" type=\"System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\">00000000-0000-0000-0000-000000000000</property>"); wp.Append(" <property name=\"Height\" type=\"string\" />"); wp.Append(" <property name=\"GhostedXslLink\" type=\"string\">main.xsl</property>"); wp.Append(" <property name=\"DisableViewSelectorMenu\" type=\"bool\">False</property>"); wp.Append(" <property name=\"DisplayName\" type=\"string\" />"); wp.Append(" <property name=\"IsClientRender\" type=\"bool\">False</property>"); if (viewSchema != null) { viewSchema.DocumentElement.SetAttribute("Name", Guid.NewGuid().ToString("B")); viewSchema.DocumentElement.SetAttribute("Url", pageUrl); viewSchema.DocumentElement.SetAttribute("Hidden", "TRUE"); viewSchema.DocumentElement.SetAttribute("DisplayName", ""); string encodedViewSchema = new XText(viewSchema.OuterXml).ToString(); wp.Append(" <property name=\"XmlDefinition\" type=\"string\">"); wp.Append(encodedViewSchema); //wp.Append(string.Format("<View Name=\"{1}\" Type=\"HTML\" Hidden=\"TRUE\" ReadOnly=\"TRUE\" OrderedView=\"TRUE\" DisplayName=\"\" Url=\"{0}\" Level=\"1\" BaseViewID=\"1\" ContentTypeID=\"0x\" ><Query><OrderBy><FieldRef Name=\"TileOrder\" Ascending=\"TRUE\"/><FieldRef Name=\"Modified\" Ascending=\"FALSE\"/></OrderBy></Query><ViewFields><FieldRef Name=\"Title\"/><FieldRef Name=\"BackgroundImageLocation\"/><FieldRef Name=\"Description\"/><FieldRef Name=\"LinkLocation\"/><FieldRef Name=\"LaunchBehavior\"/><FieldRef Name=\"BackgroundImageClusterX\"/><FieldRef Name=\"BackgroundImageClusterY\"/></ViewFields><RowLimit Paged=\"TRUE\">30</RowLimit><JSLink>sp.ui.tileview.js</JSLink><XslLink Default=\"TRUE\">main.xsl</XslLink><Toolbar Type=\"Standard\"/></View>", pageUrl, ("{" + Guid.NewGuid().ToString() + "}"))); wp.Append(" </property>"); } wp.Append(" <property name=\"InitialAsyncDataFetch\" type=\"bool\">False</property>"); wp.Append(" <property name=\"AllowHide\" type=\"bool\">True</property>"); wp.Append(" <property name=\"ParameterBindings\" type=\"string\">"); wp.Append(" <ParameterBinding Name=\"dvt_sortdir\" Location=\"Postback;Connection\"/>"); wp.Append(" <ParameterBinding Name=\"dvt_sortfield\" Location=\"Postback;Connection\"/>"); wp.Append(" <ParameterBinding Name=\"dvt_startposition\" Location=\"Postback\" DefaultValue=\"\"/>"); wp.Append(" <ParameterBinding Name=\"dvt_firstrow\" Location=\"Postback;Connection\"/>"); wp.Append(" <ParameterBinding Name=\"OpenMenuKeyAccessible\" Location=\"Resource(wss,OpenMenuKeyAccessible)\" />"); wp.Append(" <ParameterBinding Name=\"open_menu\" Location=\"Resource(wss,open_menu)\" />"); wp.Append(" <ParameterBinding Name=\"select_deselect_all\" Location=\"Resource(wss,select_deselect_all)\" />"); wp.Append(" <ParameterBinding Name=\"idPresEnabled\" Location=\"Resource(wss,idPresEnabled)\" /><ParameterBinding Name=\"NoAnnouncements\" Location=\"Resource(wss,noXinviewofY_LIST)\" /><ParameterBinding Name=\"NoAnnouncementsHowTo\" Location=\"Resource(wss,noXinviewofY_DEFAULT)\" /></property>"); wp.Append(" <property name=\"DataSourceMode\" type=\"Microsoft.SharePoint.WebControls.SPDataSourceMode, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c\">List</property>"); wp.Append(" <property name=\"AutoRefreshInterval\" type=\"int\">60</property>"); wp.Append(" <property name=\"AsyncRefresh\" type=\"bool\">False</property>"); wp.Append(" <property name=\"HelpUrl\" type=\"string\" />"); wp.Append(" <property name=\"MissingAssembly\" type=\"string\">Cannot import this Web Part.</property>"); wp.Append(" <property name=\"XslLink\" type=\"string\" null=\"true\" />"); wp.Append(" <property name=\"SelectParameters\" type=\"string\" />"); wp.Append(" </properties>"); wp.Append(" </data>"); wp.Append(" </webPart>"); wp.Append("</webParts>"); return(wp.ToString()); }
protected virtual new System.Web.UI.WebControls.Style CreateEditorPartChromeStyle(EditorPart editorPart, PartChromeType chromeType) { return(default(System.Web.UI.WebControls.Style)); }
private string GetListViewWebPartXml(Guid listId, string listUrl, XmlDocument viewSchema, string pageUrl, string title, PartChromeType chromeType) { StringBuilder wp = new StringBuilder(100); wp.Append("<WebPart xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://schemas.microsoft.com/WebPart/v2\">"); wp.AppendFormat(" <Title>{0}</Title>", title); wp.AppendFormat(" <FrameType>{0}</FrameType>", chromeType); wp.Append(" <Description></Description>"); wp.Append(" <IsIncluded>true</IsIncluded>"); wp.Append(" <PartOrder>1</PartOrder>"); wp.Append(" <FrameState>Normal</FrameState>"); wp.Append(" <Height />"); wp.Append(" <Width />"); wp.Append(" <AllowRemove>true</AllowRemove>"); wp.Append(" <AllowZoneChange>true</AllowZoneChange>"); wp.Append(" <AllowMinimize>true</AllowMinimize>"); wp.Append(" <AllowConnect>true</AllowConnect>"); wp.Append(" <AllowEdit>true</AllowEdit>"); wp.Append(" <AllowHide>true</AllowHide>"); wp.Append(" <IsVisible>true</IsVisible>"); wp.AppendFormat(" <DetailLink>{0}</DetailLink>", listUrl); wp.Append(" <HelpLink />"); wp.Append(" <HelpMode>Modeless</HelpMode>"); wp.Append(" <Dir>Default</Dir>"); wp.Append(" <PartImageSmall />"); wp.Append(" <MissingAssembly>Cannot import this Web Part.</MissingAssembly>"); wp.Append(" <PartImageLarge>/_layouts/15/images/itevent.png?rev=38</PartImageLarge>"); wp.Append(" <IsIncludedFilter />"); wp.Append(" <Assembly>Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>"); wp.Append(" <TypeName>Microsoft.SharePoint.WebPartPages.ListViewWebPart</TypeName>"); wp.Append(" <ExportControlledProperties>false</ExportControlledProperties>"); wp.Append(" <ConnectionID>00000000-0000-0000-0000-000000000000</ConnectionID>"); wp.Append(" <WebId xmlns=\"http://schemas.microsoft.com/WebPart/v2/ListView\">00000000-0000-0000-0000-000000000000</WebId>"); wp.Append(" <ListViewXml xmlns=\"http://schemas.microsoft.com/WebPart/v2/ListView\">"); if (viewSchema != null) { viewSchema.DocumentElement.SetAttribute("Name", Guid.NewGuid().ToString("B")); viewSchema.DocumentElement.SetAttribute("Url", pageUrl); viewSchema.DocumentElement.SetAttribute("Hidden", "TRUE"); viewSchema.DocumentElement.SetAttribute("DisplayName", ""); string encodedViewSchema = new XText(viewSchema.OuterXml).ToString(); wp.Append(encodedViewSchema); //wp.Append("<View Name=\"{535F259F-0C8E-4A7A-98A0-A4FCA5D222E4}\" MobileView=\"TRUE\" Type=\"CALENDAR\" Hidden=\"TRUE\" TabularView=\"FALSE\" RecurrenceRowset=\"TRUE\" DisplayName=\"\" Url=\"/sites/sandbox/SitePages/Home.aspx\" Level=\"1\" BaseViewID=\"2\" ContentTypeID=\"0x\" MobileUrl=\"_layouts/15/mobile/viewdaily.aspx\" ImageUrl=\"/_layouts/15/images/events.png?rev=38\"><Toolbar Type=\"None\" /><ViewHeader /><ViewBody /><ViewFooter /><ViewEmpty /><ParameterBindings><ParameterBinding Name=\"NoAnnouncements\" Location=\"Resource(wss,noXinviewofY_LIST)\" /><ParameterBinding Name=\"NoAnnouncementsHowTo\" Location=\"Resource(wss,noXinviewofY_DEFAULT)\" /></ParameterBindings><ViewFields><FieldRef Name=\"EventDate\" /><FieldRef Name=\"EndDate\" /><FieldRef Name=\"fRecurrence\" /><FieldRef Name=\"EventType\" /><FieldRef Name=\"WorkspaceLink\" /><FieldRef Name=\"Title\" /><FieldRef Name=\"Location\" /><FieldRef Name=\"Description\" /><FieldRef Name=\"Workspace\" /><FieldRef Name=\"MasterSeriesItemID\" /><FieldRef Name=\"fAllDayEvent\" /></ViewFields><ViewData><FieldRef Name=\"Title\" Type=\"CalendarMonthTitle\" /><FieldRef Name=\"Title\" Type=\"CalendarWeekTitle\" /><FieldRef Name=\"Location\" Type=\"CalendarWeekLocation\" /><FieldRef Name=\"Title\" Type=\"CalendarDayTitle\" /><FieldRef Name=\"Location\" Type=\"CalendarDayLocation\" /></ViewData><Query><Where><DateRangesOverlap><FieldRef Name=\"EventDate\" /><FieldRef Name=\"EndDate\" /><FieldRef Name=\"RecurrenceID\" /><Value Type=\"DateTime\"><Month /></Value></DateRangesOverlap></Where></Query></View>"); } wp.Append(" </ListViewXml>"); wp.AppendFormat(" <ListName xmlns=\"http://schemas.microsoft.com/WebPart/v2/ListView\">{0}</ListName>", listId.ToString("B").ToUpperInvariant()); wp.AppendFormat(" <ListId xmlns=\"http://schemas.microsoft.com/WebPart/v2/ListView\">{0}</ListId>", listId.ToString()); //wp.Append(" <ViewFlag xmlns=\"http://schemas.microsoft.com/WebPart/v2/ListView\">8921097</ViewFlag>"); //wp.Append(" <ViewFlags xmlns=\"http://schemas.microsoft.com/WebPart/v2/ListView\">Html Hidden RecurrenceRowset Calendar Mobile</ViewFlags>"); wp.Append(" <ViewContentTypeId xmlns=\"http://schemas.microsoft.com/WebPart/v2/ListView\">0x</ViewContentTypeId>"); wp.Append("</WebPart>"); return wp.ToString(); }
private string GetXsltListViewWebPartXml(Guid listId, string listUrl, Guid viewId, XmlDocument viewSchema, string pageUrl, string title, string jslink, PartChromeType chromeType) { StringBuilder wp = new StringBuilder(100); wp.Append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>"); wp.Append("<webParts>"); wp.Append(" <webPart xmlns=\"http://schemas.microsoft.com/WebPart/v3\">"); wp.Append(" <metaData>"); wp.Append(" <type name=\"Microsoft.SharePoint.WebPartPages.XsltListViewWebPart, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c\" />"); wp.Append(" <importErrorMessage>Cannot import this Web Part.</importErrorMessage>"); wp.Append(" </metaData>"); wp.Append(" <data>"); wp.Append(" <properties>"); wp.Append(" <property name=\"ShowWithSampleData\" type=\"bool\">False</property>"); wp.Append(" <property name=\"Default\" type=\"string\" />"); wp.Append(" <property name=\"NoDefaultStyle\" type=\"string\" null=\"true\" />"); wp.Append(" <property name=\"CacheXslStorage\" type=\"bool\">True</property>"); wp.Append(" <property name=\"ViewContentTypeId\" type=\"string\" />"); wp.Append(" <property name=\"XmlDefinitionLink\" type=\"string\" />"); wp.Append(" <property name=\"ManualRefresh\" type=\"bool\">False</property>"); wp.Append(" <property name=\"ListUrl\" type=\"string\" />"); wp.AppendFormat(" <property name=\"ListId\" type=\"System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\">{0}</property>", listId.ToString()); if (viewId != Guid.Empty) wp.AppendFormat(" <property name=\"ViewGuid\" type=\"System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\">{0}</property>", viewId.ToString("B").ToUpperInvariant()); wp.AppendFormat(" <property name=\"TitleUrl\" type=\"string\">{0}</property>", listUrl); wp.Append(" <property name=\"EnableOriginalValue\" type=\"bool\">False</property>"); wp.Append(" <property name=\"Direction\" type=\"direction\">NotSet</property>"); wp.Append(" <property name=\"ServerRender\" type=\"bool\">False</property>"); wp.Append(" <property name=\"ViewFlags\" type=\"Microsoft.SharePoint.SPViewFlags, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c\">None</property>"); wp.Append(" <property name=\"AllowConnect\" type=\"bool\">True</property>"); wp.AppendFormat(" <property name=\"ListName\" type=\"string\">{0}</property>", listId.ToString("B").ToUpperInvariant()); wp.Append(" <property name=\"ListDisplayName\" type=\"string\" />"); wp.Append(" <property name=\"AllowZoneChange\" type=\"bool\">True</property>"); wp.Append(" <property name=\"ChromeState\" type=\"chromestate\">Normal</property>"); wp.Append(" <property name=\"DisableSaveAsNewViewButton\" type=\"bool\">False</property>"); wp.Append(" <property name=\"ViewFlag\" type=\"string\" />"); wp.Append(" <property name=\"DataSourceID\" type=\"string\" />"); wp.Append(" <property name=\"ExportMode\" type=\"exportmode\">All</property>"); wp.Append(" <property name=\"AutoRefresh\" type=\"bool\">False</property>"); wp.Append(" <property name=\"FireInitialRow\" type=\"bool\">True</property>"); wp.Append(" <property name=\"AllowEdit\" type=\"bool\">True</property>"); wp.Append(" <property name=\"Description\" type=\"string\" />"); wp.Append(" <property name=\"HelpMode\" type=\"helpmode\">Modeless</property>"); wp.Append(" <property name=\"BaseXsltHashKey\" type=\"string\" null=\"true\" />"); wp.Append(" <property name=\"AllowMinimize\" type=\"bool\">True</property>"); wp.Append(" <property name=\"CacheXslTimeOut\" type=\"int\">86400</property>"); wp.AppendFormat(" <property name=\"ChromeType\" type=\"chrometype\">{0}</property>", chromeType.ToString()); wp.Append(" <property name=\"Xsl\" type=\"string\" null=\"true\" />"); if (string.IsNullOrEmpty(jslink)) wp.Append(" <property name=\"JSLink\" type=\"string\" null=\"true\" />"); else wp.AppendFormat(" <property name=\"JSLink\" type=\"string\">{0}</property>", jslink); wp.Append(" <property name=\"CatalogIconImageUrl\" type=\"string\">/_layouts/15/images/itgen.png?rev=26</property>"); wp.Append(" <property name=\"SampleData\" type=\"string\" null=\"true\" />"); wp.Append(" <property name=\"UseSQLDataSourcePaging\" type=\"bool\">True</property>"); wp.Append(" <property name=\"TitleIconImageUrl\" type=\"string\" />"); wp.Append(" <property name=\"PageSize\" type=\"int\">-1</property>"); wp.Append(" <property name=\"ShowTimelineIfAvailable\" type=\"bool\">True</property>"); wp.Append(" <property name=\"Width\" type=\"string\" />"); wp.Append(" <property name=\"DataFields\" type=\"string\" />"); wp.Append(" <property name=\"Hidden\" type=\"bool\">False</property>"); wp.AppendFormat(" <property name=\"Title\" type=\"string\">{0}</property>", title); wp.Append(" <property name=\"PageType\" type=\"Microsoft.SharePoint.PAGETYPE, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c\">PAGE_NORMALVIEW</property>"); wp.Append(" <property name=\"DataSourcesString\" type=\"string\" />"); wp.Append(" <property name=\"AllowClose\" type=\"bool\">True</property>"); wp.Append(" <property name=\"InplaceSearchEnabled\" type=\"bool\">False</property>"); wp.Append(" <property name=\"WebId\" type=\"System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\">00000000-0000-0000-0000-000000000000</property>"); wp.Append(" <property name=\"Height\" type=\"string\" />"); wp.Append(" <property name=\"GhostedXslLink\" type=\"string\">main.xsl</property>"); wp.Append(" <property name=\"DisableViewSelectorMenu\" type=\"bool\">False</property>"); wp.Append(" <property name=\"DisplayName\" type=\"string\" />"); wp.Append(" <property name=\"IsClientRender\" type=\"bool\">False</property>"); if (viewSchema != null) { viewSchema.DocumentElement.SetAttribute("Name", Guid.NewGuid().ToString("B")); viewSchema.DocumentElement.SetAttribute("Url", pageUrl); viewSchema.DocumentElement.SetAttribute("Hidden", "TRUE"); viewSchema.DocumentElement.SetAttribute("DisplayName", ""); string encodedViewSchema = new XText(viewSchema.OuterXml).ToString(); wp.Append(" <property name=\"XmlDefinition\" type=\"string\">"); wp.Append(encodedViewSchema); //wp.Append(string.Format("<View Name=\"{1}\" Type=\"HTML\" Hidden=\"TRUE\" ReadOnly=\"TRUE\" OrderedView=\"TRUE\" DisplayName=\"\" Url=\"{0}\" Level=\"1\" BaseViewID=\"1\" ContentTypeID=\"0x\" ><Query><OrderBy><FieldRef Name=\"TileOrder\" Ascending=\"TRUE\"/><FieldRef Name=\"Modified\" Ascending=\"FALSE\"/></OrderBy></Query><ViewFields><FieldRef Name=\"Title\"/><FieldRef Name=\"BackgroundImageLocation\"/><FieldRef Name=\"Description\"/><FieldRef Name=\"LinkLocation\"/><FieldRef Name=\"LaunchBehavior\"/><FieldRef Name=\"BackgroundImageClusterX\"/><FieldRef Name=\"BackgroundImageClusterY\"/></ViewFields><RowLimit Paged=\"TRUE\">30</RowLimit><JSLink>sp.ui.tileview.js</JSLink><XslLink Default=\"TRUE\">main.xsl</XslLink><Toolbar Type=\"Standard\"/></View>", pageUrl, ("{" + Guid.NewGuid().ToString() + "}"))); wp.Append(" </property>"); } wp.Append(" <property name=\"InitialAsyncDataFetch\" type=\"bool\">False</property>"); wp.Append(" <property name=\"AllowHide\" type=\"bool\">True</property>"); wp.Append(" <property name=\"ParameterBindings\" type=\"string\">"); wp.Append(" <ParameterBinding Name=\"dvt_sortdir\" Location=\"Postback;Connection\"/>"); wp.Append(" <ParameterBinding Name=\"dvt_sortfield\" Location=\"Postback;Connection\"/>"); wp.Append(" <ParameterBinding Name=\"dvt_startposition\" Location=\"Postback\" DefaultValue=\"\"/>"); wp.Append(" <ParameterBinding Name=\"dvt_firstrow\" Location=\"Postback;Connection\"/>"); wp.Append(" <ParameterBinding Name=\"OpenMenuKeyAccessible\" Location=\"Resource(wss,OpenMenuKeyAccessible)\" />"); wp.Append(" <ParameterBinding Name=\"open_menu\" Location=\"Resource(wss,open_menu)\" />"); wp.Append(" <ParameterBinding Name=\"select_deselect_all\" Location=\"Resource(wss,select_deselect_all)\" />"); wp.Append(" <ParameterBinding Name=\"idPresEnabled\" Location=\"Resource(wss,idPresEnabled)\" /><ParameterBinding Name=\"NoAnnouncements\" Location=\"Resource(wss,noXinviewofY_LIST)\" /><ParameterBinding Name=\"NoAnnouncementsHowTo\" Location=\"Resource(wss,noXinviewofY_DEFAULT)\" /></property>"); wp.Append(" <property name=\"DataSourceMode\" type=\"Microsoft.SharePoint.WebControls.SPDataSourceMode, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c\">List</property>"); wp.Append(" <property name=\"AutoRefreshInterval\" type=\"int\">60</property>"); wp.Append(" <property name=\"AsyncRefresh\" type=\"bool\">False</property>"); wp.Append(" <property name=\"HelpUrl\" type=\"string\" />"); wp.Append(" <property name=\"MissingAssembly\" type=\"string\">Cannot import this Web Part.</property>"); wp.Append(" <property name=\"XslLink\" type=\"string\" null=\"true\" />"); wp.Append(" <property name=\"SelectParameters\" type=\"string\" />"); wp.Append(" </properties>"); wp.Append(" </data>"); wp.Append(" </webPart>"); wp.Append("</webParts>"); return wp.ToString(); }
/// <summary> /// Adds a List View Web Part to the specified page. /// </summary> /// <param name="pageUrl">The page URL.</param> /// <param name="listUrl">The list URL.</param> /// <param name="title">The title.</param> /// <param name="viewTitle">Title of the view.</param> /// <param name="zoneId">The zone ID.</param> /// <param name="zoneIndex">Index within the zone.</param> /// <param name="linkTitle">if set to <c>true</c> [link title].</param> /// <param name="chromeType">Type of the chrome.</param> /// <param name="publish">if set to <c>true</c> [publish].</param> /// <returns></returns> public static Microsoft.SharePoint.WebPartPages.WebPart Add(string pageUrl, string listUrl, string title, string viewTitle, string zoneId, int zoneIndex, bool linkTitle, string jsLink, PartChromeType chromeType, bool publish) { using (SPSite site = new SPSite(pageUrl)) using (SPWeb web = site.OpenWeb()) // The url contains a filename so AllWebs[] will not work unless we want to try and parse which we don't { SPFile file = web.GetFile(pageUrl); // file.Item will throw "The object specified does not belong to a list." if the url passed // does not correspond to a file in a list. SPList list = Utilities.GetListFromViewUrl(listUrl); if (list == null) { throw new ArgumentException("List not found."); } SPView view = null; if (!string.IsNullOrEmpty(viewTitle)) { view = list.Views.Cast <SPView>().FirstOrDefault(v => v.Title == viewTitle); if (view == null) { throw new ArgumentException("The specified view was not found."); } } bool checkBackIn = false; if (file.InDocumentLibrary) { if (!Utilities.IsCheckedOut(file.Item) || !Utilities.IsCheckedOutByCurrentUser(file.Item)) { checkBackIn = true; file.CheckOut(); } // If it's checked out by another user then this will throw an informative exception so let it do so. } string displayTitle = string.Empty; Microsoft.SharePoint.WebPartPages.WebPart lvw = null; SPLimitedWebPartManager manager = null; try { manager = web.GetLimitedWebPartManager(pageUrl, PersonalizationScope.Shared); lvw = new XsltListViewWebPart(); if (list.BaseTemplate == SPListTemplateType.Events) { lvw = new ListViewWebPart(); } if (lvw is ListViewWebPart) { ((ListViewWebPart)lvw).ListName = list.ID.ToString("B").ToUpperInvariant(); ((ListViewWebPart)lvw).WebId = list.ParentWeb.ID; if (view != null) { ((ListViewWebPart)lvw).ViewGuid = view.ID.ToString("B").ToUpperInvariant(); } } else { ((XsltListViewWebPart)lvw).ListName = list.ID.ToString("B").ToUpperInvariant(); #if !SP2010 if (!string.IsNullOrEmpty(jsLink)) { ((XsltListViewWebPart)lvw).JSLink = jsLink; } #endif ((XsltListViewWebPart)lvw).WebId = list.ParentWeb.ID; if (view != null) { ((XsltListViewWebPart)lvw).ViewGuid = view.ID.ToString("B").ToUpperInvariant(); } } if (linkTitle) { if (view != null) { lvw.TitleUrl = view.Url; } else { lvw.TitleUrl = list.DefaultViewUrl; } } if (!string.IsNullOrEmpty(title)) { lvw.Title = title; } lvw.ChromeType = chromeType; displayTitle = lvw.DisplayTitle; manager.AddWebPart(lvw, zoneId, zoneIndex); } finally { if (manager != null) { manager.Web.Dispose(); manager.Dispose(); } if (lvw != null) { lvw.Dispose(); } if (file.InDocumentLibrary && Utilities.IsCheckedOut(file.Item) && (checkBackIn || publish)) { file.CheckIn("Checking in changes to page due to new web part being added: " + displayTitle); } if (publish && file.InDocumentLibrary) { file.Publish("Publishing changes to page due to new web part being added: " + displayTitle); if (file.Item.ModerationInformation != null) { file.Approve("Approving changes to page due to new web part being added: " + displayTitle); } } } return(lvw); } }
public virtual void RenderWebPart(HtmlTextWriter writer, WebPart webPart) { if (webPart == null) { throw new ArgumentNullException("webPart"); } bool flag = this.Zone.LayoutOrientation == Orientation.Vertical; PartChromeType effectiveChromeType = this.Zone.GetEffectiveChromeType(webPart); Style style = this.CreateWebPartChromeStyle(webPart, effectiveChromeType); if (!style.IsEmpty) { style.AddAttributesToRender(writer, this.Zone); } writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0"); writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "2"); writer.AddAttribute(HtmlTextWriterAttribute.Border, "0"); if (flag) { writer.AddStyleAttribute(HtmlTextWriterStyle.Width, "100%"); } else if (webPart.ChromeState != PartChromeState.Minimized) { writer.AddStyleAttribute(HtmlTextWriterStyle.Height, "100%"); } if (this.Zone.RenderClientScript) { writer.AddAttribute(HtmlTextWriterAttribute.Id, this.GetWebPartChromeClientID(webPart)); } if ((!this._designMode && webPart.Hidden) && ((this.WebPartManager != null) && !this.WebPartManager.DisplayMode.ShowHiddenWebParts)) { writer.AddStyleAttribute(HtmlTextWriterStyle.Display, "none"); } writer.RenderBeginTag(HtmlTextWriterTag.Table); switch (effectiveChromeType) { case PartChromeType.TitleOnly: case PartChromeType.TitleAndBorder: writer.RenderBeginTag(HtmlTextWriterTag.Tr); if (this._titleStyleWithoutFontOrAlign == null) { this._titleStyleWithoutFontOrAlign = this.CreateTitleStyleWithoutFontOrAlign(this.Zone.PartTitleStyle); } if (!this._titleStyleWithoutFontOrAlign.IsEmpty) { this._titleStyleWithoutFontOrAlign.AddAttributesToRender(writer, this.Zone); } writer.RenderBeginTag(HtmlTextWriterTag.Td); this.RenderTitleBar(writer, webPart); writer.RenderEndTag(); writer.RenderEndTag(); break; } if (webPart.ChromeState == PartChromeState.Minimized) { writer.AddStyleAttribute(HtmlTextWriterStyle.Display, "none"); } writer.RenderBeginTag(HtmlTextWriterTag.Tr); if (!flag) { writer.AddStyleAttribute(HtmlTextWriterStyle.Height, "100%"); writer.AddAttribute(HtmlTextWriterAttribute.Valign, "top"); } Style partStyle = this.Zone.PartStyle; if (!partStyle.IsEmpty) { partStyle.AddAttributesToRender(writer, this.Zone); } writer.AddStyleAttribute(HtmlTextWriterStyle.Padding, this.Zone.PartChromePadding.ToString()); writer.RenderBeginTag(HtmlTextWriterTag.Td); this.RenderPartContents(writer, webPart); writer.RenderEndTag(); writer.RenderEndTag(); writer.RenderEndTag(); }
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); } }
public static WebPart AddWebPartToWikiPage(SPListItem item, string webPartXml, string title, int row, int col, bool addSpace, Hashtable customReplaceText, PartChromeType chromeType, bool publish) { string wikiField = (string)item["WikiField"]; XmlDocument xd = new XmlDocument(); xd.PreserveWhitespace = true; xd.LoadXml(wikiField); // Sometimes the wikifield content seems to be surrounded by an additional div? XmlElement layoutsTable = xd.SelectSingleNode("div/div/table") as XmlElement; if (layoutsTable == null) { layoutsTable = xd.SelectSingleNode("div/table") as XmlElement; } XmlElement layoutsZoneInner = layoutsTable.SelectSingleNode(string.Format("tbody/tr[{0}]/td[{1}]/div/div", row, col)) as XmlElement; if (layoutsZoneInner == null) { throw new ArgumentException("Unable to locate row and/or column to insert HTML into."); } bool checkBackIn = false; if (item.File.InDocumentLibrary) { bool ignoreCheckOut = item.File.CheckOutType == SPFile.SPCheckOutType.None && !item.ParentList.ForceCheckout; if (!ignoreCheckOut) { if (!Utilities.IsCheckedOut(item) || !Utilities.IsCheckedOutByCurrentUser(item)) { checkBackIn = true; item.File.CheckOut(); } } // If it's checked out by another user then this will throw an informative exception so let it do so. } SPLimitedWebPartManager limitedWebPartManager = null; WebPart wpdNew = null; try { limitedWebPartManager = item.File.GetLimitedWebPartManager(System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared); wpdNew = SPCmdletImportWebPart.AddWebPart(limitedWebPartManager, item.File, webPartXml, customReplaceText); wpdNew.ChromeType = chromeType; limitedWebPartManager.AddWebPart(wpdNew, "wpz", 0); Guid storageKey = limitedWebPartManager.GetStorageKey(wpdNew); // - space element XmlElement space = xd.CreateElement("p"); XmlText text = xd.CreateTextNode(" "); space.AppendChild(text); // - wpBoxDiv XmlElement wpBoxDiv = xd.CreateElement("div"); layoutsZoneInner.AppendChild(wpBoxDiv); if (addSpace) { layoutsZoneInner.AppendChild(space); } XmlAttribute attribute = xd.CreateAttribute("class"); wpBoxDiv.Attributes.Append(attribute); attribute.Value = "ms-rtestate-read ms-rte-wpbox"; attribute = xd.CreateAttribute("contentEditable"); wpBoxDiv.Attributes.Append(attribute); attribute.Value = "false"; // - div1 XmlElement div1 = xd.CreateElement("div"); wpBoxDiv.AppendChild(div1); div1.IsEmpty = false; attribute = xd.CreateAttribute("class"); div1.Attributes.Append(attribute); attribute.Value = "ms-rtestate-read " + storageKey.ToString("D"); attribute = xd.CreateAttribute("id"); div1.Attributes.Append(attribute); attribute.Value = "div_" + storageKey.ToString("D"); // - div2 XmlElement div2 = xd.CreateElement("div"); wpBoxDiv.AppendChild(div2); div2.IsEmpty = false; attribute = xd.CreateAttribute("style"); div2.Attributes.Append(attribute); attribute.Value = "display:none"; attribute = xd.CreateAttribute("id"); div2.Attributes.Append(attribute); attribute.Value = "vid_" + storageKey.ToString("D"); item["WikiField"] = xd.OuterXml; item.Update(); if (wpdNew.Title != title) { wpdNew.Title = title; limitedWebPartManager.SaveChanges(wpdNew); } } finally { if (limitedWebPartManager != null) { limitedWebPartManager.Dispose(); } SPFile file = item.File; if (file.InDocumentLibrary && Utilities.IsCheckedOut(file.Item) && (checkBackIn || publish)) { file.CheckIn("Checking in changes to page due to new web part being added: " + title); } if (publish && file.InDocumentLibrary) { file.Publish("Publishing changes to page due to new web part being added: " + title); if (file.Item.ModerationInformation != null) { file.Approve("Approving changes to page due to new web part being added: " + title); } } } return(wpdNew); }
protected virtual Style CreateWebPartChromeStyle(WebPart webPart, PartChromeType chromeType) { if (webPart == null) { throw new ArgumentNullException("webPart"); } if ((chromeType < PartChromeType.Default) || (chromeType > PartChromeType.BorderOnly)) { throw new ArgumentOutOfRangeException("chromeType"); } // PERF: Cache these, since they are needed for every WebPart in the zone, and only vary // if one of the WebParts is selected Style webPartChromeStyle; if (chromeType == PartChromeType.BorderOnly || chromeType == PartChromeType.TitleAndBorder) { if (_chromeStyleWithBorder == null) { _chromeStyleWithBorder = CreateChromeStyleWithBorder(Zone.PartChromeStyle); } webPartChromeStyle = _chromeStyleWithBorder; } else { if (_chromeStyleNoBorder == null) { _chromeStyleNoBorder = CreateChromeStyleNoBorder(Zone.PartChromeStyle); } webPartChromeStyle = _chromeStyleNoBorder; } // add SelectedPartChromeStyle if (WebPartManager != null && webPart == WebPartManager.SelectedWebPart) { Style style = new Style(); style.CopyFrom(webPartChromeStyle); style.CopyFrom(Zone.SelectedPartChromeStyle); return style; } else { return webPartChromeStyle; } }
protected override Style CreateWebPartChromeStyle(WebPart webPart, PartChromeType chromeType) { var style = new Style(); string className = null; if (webPart.Controls.Count > 0) { string rawName = webPart.Controls[0].GetType().Name; string[] parts = rawName.Split('_'); if (parts.Length >= 2) { className = parts[parts.Length - 2]; } } style.CssClass = String.Format(String.IsNullOrEmpty(className) ? "{0} {0}_{1}" : "{0} {0}_{1} {0}_{2}", webPart.Zone.ID, webPart.ZoneIndex, className); return style; }
protected virtual new System.Web.UI.WebControls.Style CreateWebPartChromeStyle(WebPart webPart, PartChromeType chromeType) { return default(System.Web.UI.WebControls.Style); }
protected virtual new System.Web.UI.WebControls.Style CreateWebPartChromeStyle (WebPart webPart, PartChromeType chromeType) { Contract.Requires (this.Zone != null); return default(System.Web.UI.WebControls.Style); }
private string GetListViewWebPartXml(Guid listId, string listUrl, XmlDocument viewSchema, string pageUrl, string title, PartChromeType chromeType) { StringBuilder wp = new StringBuilder(100); wp.Append("<WebPart xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://schemas.microsoft.com/WebPart/v2\">"); wp.AppendFormat(" <Title>{0}</Title>", title); wp.AppendFormat(" <FrameType>{0}</FrameType>", chromeType); wp.Append(" <Description></Description>"); wp.Append(" <IsIncluded>true</IsIncluded>"); wp.Append(" <PartOrder>1</PartOrder>"); wp.Append(" <FrameState>Normal</FrameState>"); wp.Append(" <Height />"); wp.Append(" <Width />"); wp.Append(" <AllowRemove>true</AllowRemove>"); wp.Append(" <AllowZoneChange>true</AllowZoneChange>"); wp.Append(" <AllowMinimize>true</AllowMinimize>"); wp.Append(" <AllowConnect>true</AllowConnect>"); wp.Append(" <AllowEdit>true</AllowEdit>"); wp.Append(" <AllowHide>true</AllowHide>"); wp.Append(" <IsVisible>true</IsVisible>"); wp.AppendFormat(" <DetailLink>{0}</DetailLink>", listUrl); wp.Append(" <HelpLink />"); wp.Append(" <HelpMode>Modeless</HelpMode>"); wp.Append(" <Dir>Default</Dir>"); wp.Append(" <PartImageSmall />"); wp.Append(" <MissingAssembly>Cannot import this Web Part.</MissingAssembly>"); wp.Append(" <PartImageLarge>/_layouts/15/images/itevent.png?rev=38</PartImageLarge>"); wp.Append(" <IsIncludedFilter />"); wp.Append(" <Assembly>Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>"); wp.Append(" <TypeName>Microsoft.SharePoint.WebPartPages.ListViewWebPart</TypeName>"); wp.Append(" <ExportControlledProperties>false</ExportControlledProperties>"); wp.Append(" <ConnectionID>00000000-0000-0000-0000-000000000000</ConnectionID>"); wp.Append(" <WebId xmlns=\"http://schemas.microsoft.com/WebPart/v2/ListView\">00000000-0000-0000-0000-000000000000</WebId>"); wp.Append(" <ListViewXml xmlns=\"http://schemas.microsoft.com/WebPart/v2/ListView\">"); if (viewSchema != null) { viewSchema.DocumentElement.SetAttribute("Name", Guid.NewGuid().ToString("B")); viewSchema.DocumentElement.SetAttribute("Url", pageUrl); viewSchema.DocumentElement.SetAttribute("Hidden", "TRUE"); viewSchema.DocumentElement.SetAttribute("DisplayName", ""); string encodedViewSchema = new XText(viewSchema.OuterXml).ToString(); wp.Append(encodedViewSchema); //wp.Append("<View Name=\"{535F259F-0C8E-4A7A-98A0-A4FCA5D222E4}\" MobileView=\"TRUE\" Type=\"CALENDAR\" Hidden=\"TRUE\" TabularView=\"FALSE\" RecurrenceRowset=\"TRUE\" DisplayName=\"\" Url=\"/sites/sandbox/SitePages/Home.aspx\" Level=\"1\" BaseViewID=\"2\" ContentTypeID=\"0x\" MobileUrl=\"_layouts/15/mobile/viewdaily.aspx\" ImageUrl=\"/_layouts/15/images/events.png?rev=38\"><Toolbar Type=\"None\" /><ViewHeader /><ViewBody /><ViewFooter /><ViewEmpty /><ParameterBindings><ParameterBinding Name=\"NoAnnouncements\" Location=\"Resource(wss,noXinviewofY_LIST)\" /><ParameterBinding Name=\"NoAnnouncementsHowTo\" Location=\"Resource(wss,noXinviewofY_DEFAULT)\" /></ParameterBindings><ViewFields><FieldRef Name=\"EventDate\" /><FieldRef Name=\"EndDate\" /><FieldRef Name=\"fRecurrence\" /><FieldRef Name=\"EventType\" /><FieldRef Name=\"WorkspaceLink\" /><FieldRef Name=\"Title\" /><FieldRef Name=\"Location\" /><FieldRef Name=\"Description\" /><FieldRef Name=\"Workspace\" /><FieldRef Name=\"MasterSeriesItemID\" /><FieldRef Name=\"fAllDayEvent\" /></ViewFields><ViewData><FieldRef Name=\"Title\" Type=\"CalendarMonthTitle\" /><FieldRef Name=\"Title\" Type=\"CalendarWeekTitle\" /><FieldRef Name=\"Location\" Type=\"CalendarWeekLocation\" /><FieldRef Name=\"Title\" Type=\"CalendarDayTitle\" /><FieldRef Name=\"Location\" Type=\"CalendarDayLocation\" /></ViewData><Query><Where><DateRangesOverlap><FieldRef Name=\"EventDate\" /><FieldRef Name=\"EndDate\" /><FieldRef Name=\"RecurrenceID\" /><Value Type=\"DateTime\"><Month /></Value></DateRangesOverlap></Where></Query></View>"); } wp.Append(" </ListViewXml>"); wp.AppendFormat(" <ListName xmlns=\"http://schemas.microsoft.com/WebPart/v2/ListView\">{0}</ListName>", listId.ToString("B").ToUpperInvariant()); wp.AppendFormat(" <ListId xmlns=\"http://schemas.microsoft.com/WebPart/v2/ListView\">{0}</ListId>", listId.ToString()); //wp.Append(" <ViewFlag xmlns=\"http://schemas.microsoft.com/WebPart/v2/ListView\">8921097</ViewFlag>"); //wp.Append(" <ViewFlags xmlns=\"http://schemas.microsoft.com/WebPart/v2/ListView\">Html Hidden RecurrenceRowset Calendar Mobile</ViewFlags>"); wp.Append(" <ViewContentTypeId xmlns=\"http://schemas.microsoft.com/WebPart/v2/ListView\">0x</ViewContentTypeId>"); wp.Append("</WebPart>"); return(wp.ToString()); }
public static void AddLinksWP(SPWeb web, string pageUrl, string zoneId, int zoneIndex, string title, PartChromeState chromState, PartChromeType chromeType) { }
public virtual void RenderCatalogPart(HtmlTextWriter writer, CatalogPart catalogPart) { if (catalogPart == null) { throw new ArgumentNullException("catalogPart"); } PartChromeType chromeType = Zone.GetEffectiveChromeType(catalogPart); Style partChromeStyle = CreateCatalogPartChromeStyle(catalogPart, chromeType); // if (!partChromeStyle.IsEmpty) { partChromeStyle.AddAttributesToRender(writer, Zone); } writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0"); // Use CellPadding=2 to match WebPartChrome (VSWhidbey 324397) writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "2"); writer.AddAttribute(HtmlTextWriterAttribute.Border, "0"); writer.AddStyleAttribute(HtmlTextWriterStyle.Width, "100%"); writer.RenderBeginTag(HtmlTextWriterTag.Table); if (chromeType == PartChromeType.TitleOnly || chromeType == PartChromeType.TitleAndBorder) { writer.RenderBeginTag(HtmlTextWriterTag.Tr); // Can apply PartTitleStyle directly, since the title bar doesn't contain a nested table Style partTitleStyle = Zone.PartTitleStyle; if (!partTitleStyle.IsEmpty) { partTitleStyle.AddAttributesToRender(writer, Zone); } writer.RenderBeginTag(HtmlTextWriterTag.Td); RenderTitle(writer, catalogPart); writer.RenderEndTag(); // Td writer.RenderEndTag(); // Tr } if (catalogPart.ChromeState != PartChromeState.Minimized) { writer.RenderBeginTag(HtmlTextWriterTag.Tr); Style partStyle = Zone.PartStyle; if (!partStyle.IsEmpty) { partStyle.AddAttributesToRender(writer, Zone); } // For now, I don't think we should render extra padding here. People writing custom // CatalogParts can add a margin to their contents if they want it. This is not the // same as the WebPartChrome case, since for WebParts we allow people to use ServerControls, // that will likely not have a margin. (VSWhidbey 324397) // writer.AddStyleAttribute(HtmlTextWriterStyle.Padding, "5px"); writer.RenderBeginTag(HtmlTextWriterTag.Td); // RenderPartContents(writer, catalogPart); RenderItems(writer, catalogPart); writer.RenderEndTag(); // Td writer.RenderEndTag(); // Tr } writer.RenderEndTag(); // Table }
public virtual void RenderWebPart(HtmlTextWriter writer, WebPart webPart) { if (webPart == null) { throw new ArgumentNullException("webPart"); } bool vertical = (Zone.LayoutOrientation == Orientation.Vertical); PartChromeType chromeType = Zone.GetEffectiveChromeType(webPart); Style partChromeStyle = CreateWebPartChromeStyle(webPart, chromeType); // if (!partChromeStyle.IsEmpty) { partChromeStyle.AddAttributesToRender(writer, Zone); } // Render CellPadding=2 so there is a 2 pixel gap between the border and the title/body // of the WebPart. Can't render CellSpacing=2, since we want the backcolor of the title // bar to fill the title bar, and backcolor is not rendered in the CellSpacing. writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0"); writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "2"); writer.AddAttribute(HtmlTextWriterAttribute.Border, "0"); if (vertical) { writer.AddStyleAttribute(HtmlTextWriterStyle.Width, "100%"); } else if (webPart.ChromeState != PartChromeState.Minimized) { writer.AddStyleAttribute(HtmlTextWriterStyle.Height, "100%"); } if (Zone.RenderClientScript) { writer.AddAttribute(HtmlTextWriterAttribute.Id, GetWebPartChromeClientID(webPart)); } if (!_designMode && webPart.Hidden && WebPartManager != null && !WebPartManager.DisplayMode.ShowHiddenWebParts) { writer.AddStyleAttribute(HtmlTextWriterStyle.Display, "none"); } writer.RenderBeginTag(HtmlTextWriterTag.Table); if (chromeType == PartChromeType.TitleOnly || chromeType == PartChromeType.TitleAndBorder) { writer.RenderBeginTag(HtmlTextWriterTag.Tr); // PERF: Cache this, since it is needed for every WebPart in the zone if (_titleStyleWithoutFontOrAlign == null) { _titleStyleWithoutFontOrAlign = CreateTitleStyleWithoutFontOrAlign(Zone.PartTitleStyle); } // Need to apply title style here (at least backcolor and border) so the backcolor // and border include the cell padding on the td. // Should not apply font style here, since we don't want verbs to use this // font style. In IE compat mode, the font style would not be inherited anyway, // But in IE strict mode the font style would be inherited. if (!_titleStyleWithoutFontOrAlign.IsEmpty) { _titleStyleWithoutFontOrAlign.AddAttributesToRender(writer, Zone); } writer.RenderBeginTag(HtmlTextWriterTag.Td); RenderTitleBar(writer, webPart); writer.RenderEndTag(); // Td writer.RenderEndTag(); // Tr } // Render the contents of minimized WebParts with display:none, instead of not rendering // the contents at all. The contents may need to be rendered for client-side connections // or other client-side features. Also allows child controls to maintain their postback // values between requests while the WebPart is minimized. if (webPart.ChromeState == PartChromeState.Minimized) { writer.AddStyleAttribute(HtmlTextWriterStyle.Display, "none"); } writer.RenderBeginTag(HtmlTextWriterTag.Tr); if (!vertical) { writer.AddStyleAttribute(HtmlTextWriterStyle.Height, "100%"); writer.AddAttribute(HtmlTextWriterAttribute.Valign, "top"); } Style partStyle = Zone.PartStyle; if (!partStyle.IsEmpty) { partStyle.AddAttributesToRender(writer, Zone); } // Add some extra padding around the WebPart contents (VSWhidbey 324397) writer.AddStyleAttribute(HtmlTextWriterStyle.Padding, Zone.PartChromePadding.ToString()); writer.RenderBeginTag(HtmlTextWriterTag.Td); RenderPartContents(writer, webPart); writer.RenderEndTag(); // Td writer.RenderEndTag(); // Tr writer.RenderEndTag(); // Table }
public static string AddCustomWebPartsWithCustomProperty(SPWeb web, string pageUrl, string webPartName, string wpZone, int zoneIndex, PartChromeType chrome, Dictionary<string, object> customPropertiesDictionary) { try { using (SPLimitedWebPartManager manager = web.GetLimitedWebPartManager(pageUrl, PersonalizationScope.Shared)) { using (System.Web.UI.WebControls.WebParts.WebPart webPart = FindWebPart(web, webPartName, manager, "Web Part Gallery")) { if (webPart == null) return null;//check if webpart exist webPart.ChromeType = chrome; PropertyInfo[] pinProperties = webPart.GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); foreach (PropertyInfo pinProperty in pinProperties) { foreach (var customProperty in customPropertiesDictionary) { if (pinProperty.Name == customProperty.Key) { pinProperty.SetValue(webPart, customProperty.Value, null); } } } manager.AddWebPart(webPart, wpZone, zoneIndex); return webPart.ID; } } } catch (Exception ee) { EssnLog.logInfo("Error on AddCustomWebPartsWithCustomProperty in FeatureActivated."); EssnLog.logExc(ee); return null; } }
protected virtual new System.Web.UI.WebControls.Style CreateWebPartChromeStyle(WebPart webPart, PartChromeType chromeType) { Contract.Requires(this.Zone != null); return(default(System.Web.UI.WebControls.Style)); }
protected override Style CreateCatalogPartChromeStyle(CatalogPart catalogPart, PartChromeType chromeType) { Style catalogStyle = base.CreateCatalogPartChromeStyle(catalogPart, chromeType); catalogStyle.BackColor = Color.Bisque; return(catalogStyle); }
protected virtual Style CreateWebPartChromeStyle(WebPart webPart, PartChromeType chromeType) { Style style; if (webPart == null) { throw new ArgumentNullException("webPart"); } if ((chromeType < PartChromeType.Default) || (chromeType > PartChromeType.BorderOnly)) { throw new ArgumentOutOfRangeException("chromeType"); } if ((chromeType == PartChromeType.BorderOnly) || (chromeType == PartChromeType.TitleAndBorder)) { if (this._chromeStyleWithBorder == null) { this._chromeStyleWithBorder = this.CreateChromeStyleWithBorder(this.Zone.PartChromeStyle); } style = this._chromeStyleWithBorder; } else { if (this._chromeStyleNoBorder == null) { this._chromeStyleNoBorder = this.CreateChromeStyleNoBorder(this.Zone.PartChromeStyle); } style = this._chromeStyleNoBorder; } if ((this.WebPartManager != null) && (webPart == this.WebPartManager.SelectedWebPart)) { Style style2 = new Style(); style2.CopyFrom(style); style2.CopyFrom(this.Zone.SelectedPartChromeStyle); return style2; } return style; }