Audio Video Modules for ASP.NET Community Starter Kit : Part III

In this article, we will build an additional module for ASP.net CommunityStarterKit that enables you to publish audio and video contents. This module works together with Windows Media Services and it is written in C#. You have to install CommunityStarterKit (C# version for VS) to follow this article.

Implement the page for listing all section contents.

We use this page to display all contents of an audio-video section. We have create minimum a skin and the control class to control the skin.

Skin:
\Communities\Common\Themes\Default\Skins\ContentSkins \AudioVideos_AudioVideoSection.ascx

Control class : The  "AudioVideoSection" class , which is derived from the "ContentListPage" class, acts as code-behind for this particular skin. (see figure 6). Note that we have initialized the inherited attributes _skinFileName and _getContentItems. From now, the " ContentListPage" class and its ancestor "SkinnedCommunityControle" class will take over most burden jobs such like populating ContentListPage.

ContentList from us. We must only reuse or create custom controls which can be embedded as ItemTemplate in the "ContentList" instance.

  1. namespace ASPNET.StarterKit.Communities.AudioVideos  
  2. {  
  3. using System;  
  4. using System.Web.UI;  
  5. using System.Web.UI.WebControls;  
  6. using ASPNET.StarterKit.Communities;  
  7. //*********************************************************************  
  8. //  
  9. // AudioVideoSection Class  
  10. //  
  11. // Represents the default page for the Audio-Video section. This class  
  12. // displays a list of audio video listings.  
  13. //  
  14. // _skinFileName = the name of the skin to use for this section  
  15. //  
  16. // _getContentItems = the name of the method that retrieves the list of content items  
  17. //  
  18. //*********************************************************************  
  19. public class AudioVideoSection : ContentListPage  
  20. {  
  21. string _skinFileName = "AudioVideos_AudioVideoSection.ascx";  
  22. GetContentItemsDelegate _getContentItems = new GetContentItemsDelegate  
  23. AudioVideoUtility.GetAllAudioVideos);  
  24. //*********************************************************************  
  25. //  
  26. // AudioVideoSection Constructor  
  27. //  
  28. // Assigns skin and contentItems method to base ContentListPage class  
  29. //  
  30. //*********************************************************************  
  31. public AudioVideoSection() : base()  
  32. {  
  33. SkinFileName = _skinFileName;  
  34. GetContentItems = _getContentItems;  
  35. }  
  36. }  

Figure 6 (The AudioVideoSection class)

We have created "ItemAVTitle" class  to represent the title of an Audio-Video content. It will display the title of a particular content and a image link to represent the type of the content(Audio or Video).

  1. namespace ASPNET.StarterKit.Communities  
  2. {  
  3. using System;  
  4. using System.Web;  
  5. using System.Text;  
  6. using System.Web.UI;  
  7. using System.Web.UI.WebControls;  
  8. using System.Text.RegularExpressions;  
  9. using ASPNET.StarterKit.Communities.Books;  
  10. //*********************************************************************  
  11. //  
  12. // ItemAVTitle Class  
  13. //  
  14. // Represents a audiovideo Title in a ContentList template  
  15. //  
  16. //*********************************************************************  
  17. public class ItemAVTitle : WebControl  
  18. {  
  19. private string _externalIconsrc="~/Communities/Common/Images/Video.gif";  
  20. //*********************************************************************  
  21. //  
  22. // ItemLinkTitle Constructor  
  23. //  
  24. // Assign a default css style (the user can override)  
  25. //  
  26. //*********************************************************************  
  27. public ItemAVTitle()  
  28. {  
  29. CssClass = "itemLinkTitle";  
  30. EnableViewState = false;  
  31. }   
  32. //*********************************************************************  
  33. //  
  34. // ExternalIconSrc Property  
  35. //  
  36. // Allows users to assign a custom icon for external links  
  37. //  
  38. //*********************************************************************  
  39. public string ExternalIconSrc  
  40. {  
  41. get { return _externalIconSrc; }  
  42. set { _externalIconSrc = value; }  
  43. }  
  44. //*********************************************************************  
  45. //  
  46. // ContentPageID Property  
  47. //  
  48. // Represents the contentpageID of the item  
  49. //  
  50. //*********************************************************************  
  51. public int ContentPageID  
  52. {  
  53. get  
  54. {  
  55. if (ViewState["ContentPageID"] == null)  
  56. return -1;  
  57. else  
  58. return (int)ViewState["ContentPageID"];  
  59. }  
  60. set  
  61. {  
  62. ViewState["ContentPageID"] = value;  
  63. }  
  64. }  
  65. //*********************************************************************  
  66. //  
  67. //Title Property  
  68. //  
  69. // Represents the Title of the item  
  70. //  
  71. //*********************************************************************  
  72. public string Title  
  73. {  
  74. get  
  75. {  
  76. if (ViewState["Title"] == null)  
  77. return String.Empty;  
  78. else  
  79. return (string)ViewState["Title"];  
  80. }  
  81. set  
  82. {  
  83. ViewState["Title"] = value;  
  84. //*********************************************************************  
  85. //  
  86. // OnDataBinding Method  
  87. //  
  88. // Get the title from the container's DataItem property  
  89. //  
  90. //*********************************************************************  
  91. override protected void OnDataBinding(EventArgs e)  
  92. {  
  93. ContentItem item;  
  94. if (NamingContainer is ContentItem)  
  95. item = (ContentItem)NamingContainer;  
  96. else  
  97. item = (ContentItem)NamingContainer.NamingContainer;  
  98. AudioVideoInfo objAVInfo = (AudioVideoInfo)item.DataItem;  
  99. ContentPageID = objAVInfo.ContentPageID;  
  100. Title=objAVInfo.Title;  
  101. // Fix the icon depend from the content  
  102. if(objAVInfo.Video!=true)  
  103. {  
  104. _externalIconsrc="~/Communities/Common/Images/Audio.gif";  
  105. }  
  106. }  
  107. /// <summary>  
  108. /// compose the visual representation  
  109. /// </summary>  
  110. override protected void CreateChildControls()  
  111. {  
  112. // Image Link  
  113. HyperLink hlImgBroadcast = new HyperLink();  
  114. hlImgBroadcast.ImageUrl=Page.ResolveUrl(_externalIconSrc);  
  115. hlImgBroadcast.Text=Title;  
  116. string strRedirect=CommunityGlobals.CalculatePath(String.Format"{0}.aspx",ContentPageID));  
  117. hlImgBroadcast.NavigateUrl=strRedirect;  
  118. this.Controls.Add(hlImgBroadcast);  
  119. // gap  
  120. LiteralControl lControl=new LiteralControl("  ");  
  121. this.Controls.Add(lControl);  
  122. // Text Link  
  123. HyperLink hlBroadcast = new HyperLink();  
  124. hlBroadcast.Text=Title;  
  125. hlBroadcast.NavigateUrl=strRedirect;  
  126. this.Controls.Add(hlBroadcast);  
  127. }   
  128. }  
  129. }  
  130. }  
Figure 7

Additionally, we have created an another custom control "AudioVideoEditControl" (figure 7)  which is used to navigate to other related pages from section page.

  1. using System.ComponentModel;  
  2. namespace ASPNET.StarterKit.Communities  
  3. {  
  4. using System;  
  5. [Designer(typeof(ASPNET.StarterKit.Communities.CommunityDesigner))]  
  6. public class AudioVideoEditContent : EditContent  
  7. {  
  8. /// <summary>  
  9. /// This class is used to as Navigator  
  10. /// and this control is embedded in AudioVideoSecton.ascx  
  11. /// </summary>  
  12. public AudioVideoEditContent()  
  13. {  
  14. if (Context != null)  
  15. {  
  16. PageInfo _pageInfo = (PageInfo)Context.Items["PageInfo"];  
  17. int contentPageID = _pageInfo.ID;  
  18. AddUrl = "AudioVideos_AddAudioVideo.aspx";  
  19. EditUrl = String.Format("AudioVideos_EditAudioVideo.aspx?id={0}", contentPageID);  
  20. DeleteUrl = String.Format("ContentPages_DeleteContentPage.aspx?id={0}", contentPageID);  
  21. MoveUrl = String.Format("ContentPages_MoveContentPage.aspx?id={0}",  
  22. ontentPageID);  
  23. CommentUrl = String.Format("Comments_AddComment.aspx?id={0}", contentPageID);  
  24. ModerateUrl = "Moderation_ModerateSection.aspx";  
  25. }  
  26. }  
  27. }  
  28. }
Figure 7

Finally , we must register this page as section page using the following the statement
  1. /* registers AudioVideoSection as section PageType*/  
  2. IF NOT EXISTS (SELECT * FROM Community_PageTypes WHERE pageType_Name='AudioVideoSection')  
  3. BEGIN  
  4. INSERT INTO Community_PageTypes  
  5. (  
  6. pageType_Name,  
  7. pageType_Description,  
  8. pageType_PageContent,  
  9. pageType_isSectionType  
  10. )  
  11. VALUES  
  12. (  
  13. 'AudioVideoSection',  
  14. 'Contains AudioVideo listings',  
  15. 'ASPNET.StarterKit.Communities.AudioVideos.AudioVideoSection',  
  16. 1  
  17. )  
  18. END  
  19. Go

continue article