PART 7
Loose Ends
Right here I’m going to do a quick tidy up of some loose ends then proceed to package the module so it can be installed easily.
I’m going to add a couple of entries to my resource file for the edit control, so that my edit control is titled correctly and that there is text for the help option.
ControlTitle_edit.Text Edit Random Image
ModuleHelp.Text This module displays a random image from a user defined list of images
I also need to add the help option to the view control by adding this to my resource file.
ModuleHelp.Text This module displays a random image from a user defined list of images
If you include any HTML markup in your help text entries you need to make sure that you correctly escape the < and > characters. The reason being the resource file is a XML file and these characters will cause your file to be invalid. Simply replace < with < and > >
I’m going to add validation to the alt tag field in the edit control to make this field mandatory. This is a pretty easy thing to do with .Net so I’ll leave you to do this yourself.
The other thing I’m going to-do is localise all my link buttons on the edit control, do this I’m going to add an attribute called resourcekey to the link button tags then create an entry in my resource file. So for example here is tag for the Done link button.
<asp:linkbutton id="cmdDone" runat="server" resourcekey="cmdDone"
CssClass="CommandButton">Done</asp:linkbutton>
So I now create entry in the resource file for this control with a name of “cmdDone.Text” and a value of “Done”.
Following this approach will allow us or others to easily localise this module should that have a need to do this, as you can see it really easy to do.
Right the only other code we need to write is the import and export routines, which we’ll do right now. Open up the BTBRandomImageController.cs which is located in the components folder. Find the ExportModule method, and replace it with this code
public string ExportModule(int ModuleID)
{
StringBuilder sb;
ArrayList imageList;
imageList = this.GetByModules(ModuleID);
if(imageList.Count > 0)
{
sb = new StringBuilder();
sb.Append("<RandomImages>");
foreach(BTBRandomImageInfo image in imageList)
{
sb.Append("<RandomImage>");
sb.Append("<imageSrc>");
sb.Append(Globals.XMLEncode(image.imageSrc));
sb.Append("</imageSrc>");
sb.Append("<imageAlt>");
sb.Append(Globals.XMLEncode(image.imageAlt));
sb.Append("</imageAlt>");
sb.Append("</RandomImage>");
}
sb.Append("</RandomImages>");
return sb.ToString();
}
else
return "";
}
Simple eh? That is all the code we need to export our module’s data.
I just want to make one comment about the code above, if you take a look you’ll see we are using a method called Globals.XMLEncode. This method is used since the content is exported into a XML file from DotNetNuke, we need to ensure that the content we export is escaped so as not to make the XML file invalid.
From version 3.2.x of DotNetNuke the Globals.XMLEncode has been marked as obsolete and instead you should use this method DotNetNuke.Common.Utilities.XmlUtils.XMLEncode. However doing so will mean that our module doesn’t work with 3.0 or 3.1 installations since there is no XmlUtils.XMLEncode method in these versions. Therefore I’m going to use the obsolete method to maintain wider support for all versions of 3.x.
The code for the import is even simpler
public void ImportModule(int ModuleID, string Content, string Version, int UserId)
{
XmlNode xmlImages;
xmlImages = Globals.GetContent(Content, "RandomImages");
foreach(XmlNode xmlImage in xmlImages)
{
BTBRandomImageInfo image = new BTBRandomImageInfo();
image.moduleID = ModuleID;
image.imageSrc = xmlImage["imageSrc"].InnerText;
image.imageAlt = xmlImage["imageAlt"].InnerText;
this.Add(image);
}
}
You’ll also need to add these two lines to the top of the class so we can use the XmlNode and StringBuilder option.
using System.Text;
using System.Xml;
Build the solution and test that you can import and export data from our module.
<< Previous Page Next Page >>