protected override void RenderContents(HtmlTextWriter writer) { WebPart webpart = WebPartToEdit; Debug.WriteLine(webpart.GetType()); Assembly current = Assembly.GetAssembly(webpart.GetType()); Debug.WriteLine(current); Assembly framework = Assembly.GetExecutingAssembly(); Debug.WriteLine(framework); writer.WriteLine("<br><center><font color='blue'>"); writer.WriteLine(current.GetName().Name.Replace(".", "<br>")); writer.WriteLine("</font><br><br>"); writer.WriteLine("Version " + current.GetName().Version); writer.WriteLine("<br>"); writer.WriteLine("*Framework " + framework.GetName().Version); writer.WriteLine("<br>"); writer.WriteLine("Copyright (c) 2008<br>"); writer.AddAttribute(HtmlTextWriterAttribute.Href, "http://www.spsprofessional.com"); writer.AddAttribute(HtmlTextWriterAttribute.Target, "_blank"); writer.RenderBeginTag(HtmlTextWriterTag.A); writer.Write("<br><b>SPSProfessional<br>Professional SharePoint Components</b>"); writer.RenderEndTag(); writer.Write("<br><br>"); }
protected override void RenderContents(HtmlTextWriter writer) { WebPart webpart = WebPartToEdit; Debug.WriteLine(webpart.GetType()); Assembly current = Assembly.GetAssembly(webpart.GetType()); Debug.WriteLine(current); Assembly framework = Assembly.GetExecutingAssembly(); FileVersionInfo frameworkFileViersion = FileVersionInfo.GetVersionInfo(framework.Location); FileVersionInfo currentFileViersion = FileVersionInfo.GetVersionInfo(current.Location); Debug.WriteLine(framework); Debug.WriteLine(SPSTools.GetWssVersion()); writer.WriteLine("<br><center><font color='blue'>"); writer.WriteLine(current.GetName().Name.Replace(".", "<br>")); writer.WriteLine("</font><br><br>"); writer.WriteLine("Version DLL " + current.GetName().Version); writer.WriteLine("<br/>"); writer.WriteLine("Version Rev " + currentFileViersion.FileVersion); writer.WriteLine("<br/>"); writer.WriteLine("Framework Base " + framework.GetName().Version); writer.WriteLine("<br/>"); writer.WriteLine("Framework Version " + frameworkFileViersion.FileVersion); writer.WriteLine("<br/>"); writer.WriteLine("Wss Version " + SPSTools.GetWssVersion()); writer.WriteLine("<br/><br/>"); writer.WriteLine("Copyright (c) 2008/2009<br>"); writer.AddAttribute(HtmlTextWriterAttribute.Href, "http://www.spsprofessional.com"); writer.AddAttribute(HtmlTextWriterAttribute.Target, "_blank"); writer.RenderBeginTag(HtmlTextWriterTag.A); writer.Write("<br><b>SPSProfessional<br>Professional SharePoint Components</b>"); writer.RenderEndTag(); writer.Write("<br><br>"); }
public static bool IsWebPartGridListView(WebPart wp) { if (wp == null) { return(false); } var asm = Assembly.Load(Resources.WebPartsAssembly); if (asm == null) { throw new DllNotFoundException(Resources.WebPartsAssembly + ", not found"); } var types = asm.GetTypes(); var gridListViewType = types.FirstOrDefault(t => t.Name == Resources.WebPartsGridListView); if (gridListViewType == null) { throw new EntryPointNotFoundException(Resources.WebPartsAssembly + ", does not contain a definition for: " + Resources.WebPartsGridListView); } var wpType = wp.GetType(); return(gridListViewType.Equals(wpType)); }
/// <summary> /// Check all webpart in the specified webpartpage /// </summary> /// <param name="CurrentFile"></param> protected void CrawlWebPartPage(SPFile CurrentFile) { using (SPWeb web = CurrentFile.ParentFolder.ParentWeb) { SPWebPartCollection parts = web.GetWebPartCollection(CurrentFile.Url, Storage.Shared); if (parts != null) { //OnTrace("Start search " + CurrentFile.Url.ToString() + " webpart's page...", ""); for (int i = 0; i < parts.Count; i++) { using (WebPart wptWebPart = parts[i]) { if (WebPartInWebPartList(wptWebPart)) { string[] webPartNames = wptWebPart.ToString().Split('.'); string WebPartSmallName = webPartNames[webPartNames.Length - 1].ToString(); OnTrace("Start search webpart " + WebPartSmallName, ""); try { PropertyInfo[] pinProperties = wptWebPart.GetType().GetProperties( BindingFlags.Public | BindingFlags.Instance); try { foreach (PropertyInfo p in pinProperties) { if (FindReplaceWebPartProperty(wptWebPart, p)) { parts.SaveChanges(wptWebPart.StorageKey); } } } catch (Exception ex) { string sre = ex.Message; } } catch (Exception ex) { string s = ex.Message; } OnTrace("Finish search webpart " + WebPartSmallName, ""); } GC.Collect(); GC.WaitForPendingFinalizers(); } } } GC.Collect(); GC.WaitForPendingFinalizers(); } //OnTrace("Finish search " + CurrentFile.Url.ToString() + " webpart's page...", ""); }
public override void SyncChanges() { WebPart webPart = this.WebPartToEdit; int i = 0; foreach (string propertyName in PropertyNames) { PropertyInfo propertyInfo = webPart.GetType().GetProperty(propertyName); Type propertyType = propertyInfo.PropertyType; object propertyValue = propertyInfo.GetValue(webPart, null); IDisplayableClass displayClass = WebPartServiceLocator.Current.DisplayableClasses.FirstOrDefault(c => c.IsAppliable(propertyType)); Control control = (Control)this.FindControl("control" + i.ToString()); displayClass.SetControlValue(control, propertyValue); i++; } }
public override bool ApplyChanges() { WebPart webPart = this.WebPartToEdit; int i = 0; foreach (string propertyName in this.PropertyNames) { PropertyInfo propertyInfo = webPart.GetType().GetProperty(propertyName); Type propertyType = propertyInfo.PropertyType; IDisplayableClass displayClass = WebPartServiceLocator.Current.DisplayableClasses.FirstOrDefault(c => c.IsAppliable(propertyType)); Control control = this.FindControl("control" + i.ToString()); propertyInfo.SetValue(webPart, displayClass.GetControlValue(control), null); i++; } return(true); }
//public void SetProperty(WebPart webpart, string property, object value) //{ // try // { // var type = webpart.GetType(); // var pi = type.GetProperty(property); // if (pi != null) // { // pi.SetValue(webpart, value, null); // } // } // catch (Exception) // { // } //} //public void SetProperty(WebPart webpart, string property, object value) //{ // var type = webpart.GetType(); // var pi = type.GetProperty(property); // if (pi != null) // { // Object objValue = Convert.ChangeType(value, pi.PropertyType); // pi.SetValue(webpart, objValue, null); // } //} public void SetProperty(WebPart webpart, string property, object value) { var type = webpart.GetType(); System.Reflection.PropertyInfo pi = type.GetProperty(property); if (pi != null) { Object objValue = null; if (System.Reflection.PropertyInfo.Equals(pi.PropertyType.ToString(), "System.Web.UI.WebControls.WebParts.PartChromeType")) { objValue = System.Web.UI.WebControls.WebParts.PartChromeType.None; } else { objValue = Convert.ChangeType(value, pi.PropertyType); } pi.SetValue(webpart, objValue, null); } }
public override void ExportWebPart(WebPart webPart, XmlWriter writer) { if (webPart is IConfigurableWebPart) { writer.WriteStartElement("webPart"); writer.WriteAttributeString("type", SerializationServices.ShortAssemblyQualifiedName(webPart.GetType().AssemblyQualifiedName)); IConfiguration config = (webPart as IConfigurableWebPart).Configuration; SerializationServices.Serialize(config, writer); writer.WriteEndElement(); } else { base.ExportWebPart(webPart, writer); } }
protected override void CreateChildControls() { WebPart webPart = this.WebPartToEdit; int i = 0; foreach (string propertyName in PropertyNames) { PropertyInfo propertyInfo = webPart.GetType().GetProperty(propertyName); Type propertyType = propertyInfo.PropertyType; object[] attributes = propertyInfo.GetCustomAttributes(false); IDisplayableClass displayClass = WebPartServiceLocator.Current.DisplayableClasses.FirstOrDefault(c => c.IsAppliable(propertyType)); Control control = displayClass.CreateControl(); control.ID = "control" + i.ToString(); Panel sectionHead = new Panel(); sectionHead.CssClass = "UserSectionHead"; WebDisplayNameAttribute displayNameAttribute = attributes.OfType <WebDisplayNameAttribute>().FirstOrDefault(); if (displayNameAttribute != null) { if (displayClass.IsControlInHeaderSection()) { sectionHead.Controls.Add(control); sectionHead.Controls.Add(new LiteralControl(" ")); } sectionHead.Controls.Add(new LiteralControl(displayNameAttribute.DisplayName)); } this.Controls.Add(sectionHead); if (!displayClass.IsControlInHeaderSection()) { Panel sectionBody = new Panel(); sectionBody.CssClass = "UserSectionBody"; sectionBody.Style.Add("padding-bottom", "8px"); sectionBody.Controls.Add(control); this.Controls.Add(sectionBody); } if (i < PropertyNames.Length - 1) { Panel sectionDottedLine = new Panel(); sectionDottedLine.CssClass = "UserDottedLine"; sectionDottedLine.Style.Add("width", "100%"); sectionDottedLine.Style.Add("margin-bottom", "5px"); this.Controls.Add(sectionDottedLine); } i++; } SyncChanges(); base.CreateChildControls(); }