Adding Podcasting in .Text as I did it requires the addition or modification of the following components:
1) File Upload component in the Admin New and Edit Post forms.
2) SQL Table to hold information about the attachment (and retrieval stored proc.)
3) An Attachment Business Object
4) Data Layer methods to retrieve the attachment by PostID and populate the Attachment data object
5) Modifying the RSSWriter to add the ENCLOSURE tag.
6) Addition of attachment link in the post display.
File Upload component in the Admin New and Edit Post forms
Because this is not a podcast-centric site and attachments would be added to posts only occasionally (at first, anyway), I approached attachments as an optional design and UI element. With this in mind, an "Add Attachment" expanding subform was added to the Admin New and Edit Post form, which, due to the smart architectural approach of ScottW, required me to add it only one time for both New and Edit functions. The MimeType dropdown items were pulled from an XML file to be easily modified by the client.
SQL Table to hold information about the attachment (and retrieval stored proc.)
Click here to display the table layout and generation script.
An Attachment Business Object
Again because of the optional nature of attachments for this particular community site, I created a separate Attachment business object rather than extend the Entry object or inherit from it like the CategoryEntry object. I wanted to keep the logic of Attachments and Entries as separate as possible. The complete Attachment business object is available here.
Data Layer methods to retrieve the attachment by PostID and populate the Attachment data object
Attachment attachment = Entries.GetAttachment(PostID) is the primary retrieval method call to determine the presence of a post attachment, and if available, do something with it. Below is the Entries.Attachment() method followed by the core of the DTO and DB data layer methods as found in the LoadAttachment() method of the DataHelper Class.
public static Attachment GetAttachment(int postID)
{
return DTOProvider.Instance().GetAttachment(postID);
}
public static Attachment LoadAttachment(IDataReader reader)
{
Dottext.Framework.EC.XMLUtils oXMLUtils = new Dottext.Framework.EC.XMLUtils();
Attachment a = new Attachment();
a.AttachMimeType = (string)reader["MimeType"];
a.AttachSizeInBytes = (int)reader["SizeInBytes"];
a.AttachFileName = (string)reader["FileName"];
string host = ConfigurationSettings.AppSettings["AggregateUrl"];
string urlExt = oXMLUtils.getvalue("URLExtension").Trim();
string path = oXMLUtils.getvalue("AttachmentURLPath");
a.AttachmentURL = host + urlExt + "/" + path + "/" + a.AttachFileName;
return a;
}
Modifying the RSSWriter to add the ENCLOSURE tag
This was the most simple aspect of adding Podcasting support to .Text: updating the BaseRSSWriter and MainFeed classes.
Attachment attachment = Dottext.Framework.Entries.GetAttachment(entry.EntryID);
if (attachment != null)
{
this.WriteStartElement("enclosure");
this.WriteAttributeString("url", attachment.AttachmentURL);
this.WriteAttributeString("length", attachment.AttachSizeInBytes.ToString());
this.WriteAttributeString("type", attachment.AttachMimeType);
this.WriteEndElement();
}
Addition of the attachment link in the post display
This is an attachments feature that I completely overlooked in the initial project estimate: adding attachment links to posts and post listings. Fortunately it was a very easy matter of duplicating the logic of adding the enclosure tag to the RSS feed. Below is a code excerpt followed by how an attachment link appears on a single post entry.
Attachment attachment = Entries.GetAttachment(entry.EntryID);
if (attachment != null)
{
Literal bars = (Literal)e.Item.FindControl("bars");
bars.Visible = true;
HyperLink hlAttachment = (HyperLink)e.Item.FindControl("hlAttachment");
hlAttachment.NavigateUrl = attachment.AttachmentURL;
hlAttachment.Text = "Attachment Available";
}
So if you're a .Text user and want to get into Podcasting, here's how to get rolling. Good luck and let me know if I can answer any questions you might have in adding Podcasting support to .Text.