Hallo Joe,
I have just stumbled upon mojoPortal and wanted to check out a few thing - so far I must say I'm impressed with your work!
Is it possible to use webparts that have user editable properties exposed? I have tried to get my own web part into the system - which has been very easy thanks to the import mechanism - but I have not found a way to edit the web parts properties.
I have included a sample source code for a property and for my basic rss reader web part.
Thanks again for your great work and dedication - it is really appreciated!
Chris
// sample code for a useder editable property
[Personalizable, WebBrowsable, WebDescription("Number of articles to be displayed")]
public int ItemCount
{
get { return itemCount; }
set { itemCount = value; }
}
// Here is my code for a very basic sample webpart:
using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Xml;
namespace tripunkt.dbToolkit.Portal.WebParts
{
public class TriRssWebPart : WebPart
{
private string rssUrl;
private int itemCount;
private bool blShowImage;
private bool blShowDescription;
public TriRssWebPart()
{
this.Title = "Christophers demo Newsfeed Webpart";
this.AllowClose = true;
this.AllowMinimize = true;
}
[Personalizable, WebBrowsable, WebDescription("Show Feed Image")]
public bool ShowImage
{
get { return blShowImage; }
set { blShowImage = value; }
}
[Personalizable, WebBrowsable, WebDescription("Show Feed Description")]
public bool ShowDesciption
{
get { return blShowDescription; }
set { blShowDescription = value; }
}
[Personalizable, WebBrowsable, WebDescription("Number of articles to be displayed")]
public int ItemCount
{
get { return itemCount; }
set { itemCount = value; }
}
[Personalizable, WebBrowsable, WebDescription("URL of the RSS Feed")]
public string RssUrl
{
get { return rssUrl; }
set { rssUrl = value; }
}
[Personalizable, WebBrowsable]
public override Unit Height
{
get
{
return base.Height;
}
set
{
base.Height = value;
}
}
[Personalizable, WebBrowsable]
public override Unit Width
{
get
{
return base.Width;
}
set
{
base.Width = value;
}
}
private string GetContent()
{
StringBuilder sb = new StringBuilder();
//sb.Append(string.Format("Zeige {0} Artikel von Feed {1} an.", itemCount, rssUrl));
XmlDocument doc = new XmlDocument();
try
{
doc.Load(rssUrl);
}
catch (Exception e)
{
return string.Format("<b>Document {0} could not be loaded.</b>", rssUrl);
}
XmlElement root = doc.DocumentElement;
foreach (XmlNode channel in root.ChildNodes)
{
try
{
string channelTitle = channel["title"].InnerText;
//sb.Append("<b>" + channelTitle + "</b>");
this.Title = channelTitle;
}
catch (Exception ex) { }
if (blShowImage)
{
try
{
sb.Append(" <center><img src=\"" + channel["image"]["url"].InnerText + "\"></center><br/>");
}
catch (Exception ex) { }
}
if (blShowDescription)
{
try
{
sb.Append("<small>" + channel["description"].InnerText + "</small><br/>");
}
catch (Exception ex) { }
}
//sb.Append("</br>");
sb.Append("<ul>");
int count = itemCount;
foreach (XmlNode item in channel.ChildNodes)
{
if (item.LocalName.Equals("item") == false)
continue;
if (count < 1)
break;
count--;
sb.Append("<li>");
try
{
sb.Append("<small><b>" + item["title"].InnerText + "</b></small>");
}
catch (Exception ex) { }
try
{
sb.Append("<br/><small>" + item["description"].InnerText + "</small>");
}
catch (Exception ex) { }
try
{
sb.Append(" <small><a href = \"" + item["link"].InnerText + "\">[...]</a></small>");
}
catch (Exception ex) { }
try
{
sb.Append(" <small><a href = \"" + item["enclosure"].Attributes["url"].InnerText + "\">[->]</a></small>");
}
catch (Exception ex) { }
sb.Append("</li>");
}
sb.Append("</ul>");
}
return sb.ToString();
}
protected override void CreateChildControls()
{
{
Controls.Clear();
Literal literal = new Literal();
literal.Text = GetContent();
this.Controls.Add(literal);
ChildControlsCreated = true;
}
}
protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)
{
base.RenderContents(writer);
}
}
}