True to my promise, I did work stuff today. The good news was that I got to add functionality to the DotNetNuke Feedback control on our company website. Yeah, its nice to make the decisions on what apps we use. Changes I made were added a Bcc recipient pulled from a custom configuration XML file, a dropdown list from an XML datafile to select the respective company contact to receive the mail, and a checkbox for noting if the individual requests to be contacted. Working with DotNetNuke code (or .Text or nGallery) is a lot more fun than working on the apps I authored from scratch.
What might be interesting is how I populate the contacts dropdown from XML with two statements -- in the feedback.ascx.vb Page_Load()
Dim fsData As FileStream = New FileStream(Server.MapPath("/xml/contacts.xml"), FileMode.Open)
XMLUtil.DoDropDownListXML(ddContacts, fsData, "email_addr", "title", XMLUtil.GetValue("DefaultContactText"))
The component DoDropDownListXML looks like so:
Public Shared Sub DoDropDownListXML(ByVal ddList As DropDownList, ByVal fsXMLData As FileStream, ByVal DataValueField As String, ByVal DataTextField As String, ByVal FindByValue As String)
Dim ds As DataSet = New DataSet
' We're not passing a schema so use the same name and path as XMLDataFile
Dim schema As String = fsXMLData.Name.Replace(".xml", ".xsd")
ds.ReadXmlSchema(schema)
ds.ReadXml(fsXMLData, XmlReadMode.IgnoreSchema)
ds.Tables(0).TableName = "table"
Dim dt As DataTable = ds.Tables("table")
Dim dv As DataView = dt.DefaultView
dv.Sort = DataTextField
ddList.DataSource = dv
ddList.DataTextField = DataTextField
ddList.DataValueField = DataValueField
ddList.DataBind()
If FindByValue <> "0" Then
Try
ddList.Items.FindByText(FindByValue).Selected = True
Catch ex As Exception
ddList.Items.Insert(0, "")
ddList.SelectedIndex = 0
End Try
Else
ddList.Items.Insert(0, "")
ddList.SelectedIndex = 0
End If
fsXMLData.Close()
End Sub
The static XMLUtil.GetValue() function is a simple method I use all the time so I don't have to use the web.config AppSettings. In this case I'm reading from the Dnn.config file I added for custom runtime configuration setting changes made to DotNetNuke.
Public Shared Function GetValue(ByVal key As String) As String
Dim valout As String = String.Empty
Try
Dim doc As XmlDocument = New XmlDocument
doc.Load(System.Web.HttpContext.Current.Server.MapPath("/dbvt/xml/dnn.config"))
Dim node As XmlNode = CType(doc.DocumentElement.SelectSingleNode("/dnn/item[code='" + key + "']"), XmlNode)
valout = node.ChildNodes(1).InnerText
Catch ex As Exception
valout = "?69?"
End Try
Return valout
End Function