Dave Burke : Freelance .NET Web Developer specializing in Online Communities

.Text update Categories function

You'll see a strange (and wide!) button on the familiar .Text admin Edit Post page excerpt below.  Update Categories Only.




I wrote this function to manipulate categories without changing any other qualities of the original post, specifically, not put them back in the RSS channel (more specifically, avoid updating their Date value so that aggregators don't view them as new and download them again.)  I will be expanding the Categories concept on my blog and adding Series listings.  I originally referred to Series as “Micro Categories“ (weird), but the idea is the same:  Series listings will serve as SubCategories.  More on that here.

As I said in that referenced post, the intelligence is already in .Text to do this.  I only had to isolate it, which I was able to do from start to finish and online in less than an hour.  I wanted to list a few interesting coding concepts of the update.

I added the LinkButton as usual

protected System.Web.UI.WebControls.LinkButton lkbUpdateCategory;

To bypass Scott's cool “Are you sure you want to navigate away from this page?...“ popup confirmation (which is very interesting implementation of client-side javascript) I added the following to a SetConfirmation() method.  You'll have to explore Scott's code to learn why.

this.lkbUpdateCategory.Attributes.Add("OnClick",ConfirmationPage.ByPassFuncationName);

There was already a Entries.SetEntryCategoryList(PostID,Categories); method in the datalayer so I extracted this functionality to its own method.

// DBVT CODE BLOCK BEGIN
private void UpdateCategories()

 if(Page.IsValid)
 {
  string successMessage = Constants.RES_SUCCESSCATEGORYUPDATE;

  try
  {
   if (PostID > 0)
   {
    successMessage = Constants.RES_SUCCESSCATEGORYUPDATE;
    ArrayList al = new ArrayList();
    int count = cklCategories.Items.Count;

    for (int i =0; i    {
     if (cklCategories.Items[i].Selected)
     {
      al.Add(Int32.Parse(cklCategories.Items[i].Value));
     }
    }

    int[] Categories = (int[])al.ToArray(typeof(int));
    Entries.SetEntryCategoryList(PostID,Categories);

    BindList();
    this.Messages.ShowMessage(successMessage);
    this.ResetPostEdit(false);
   }
   else
    this.Messages.ShowError(Constants.RES_FAILURECATEGORYUPDATE
     + " There was a baseline problem updating the post categories.");  
  }
  catch(Exception ex)
  {
   this.Messages.ShowError(String.Format(Constants.RES_EXCEPTION,
    Constants.RES_FAILUREEDIT, ex.Message));
  }
  finally
  {
   Results.Collapsible = false;
  }
 }
}
// DBVT CODE BLOCK END

I wanted that sweet little confirmation message on the EditPosts page upon completion of the category update (shown below), so I added that piece from the original UpdatePost() method as well.  The constant values used in the .Text Admin project are located in /WebUI/Utilities.cs, so they were added.

internal const string RES_SUCCESSCATEGORYUPDATE = "Categories updated successfully.";
internal const string RES_FAILURECATEGORYUPDATE = "Category Update failed.";





I tested the update to make sure that it worked as I wanted it, that is, posts weren't updated and as a result were not downloaded twice into NewsGator when I retrieved my news feeds.  During the testing, however I realized that only the top 15 (or 25 or whatever your feed count setting is) are affected by the double feed distribution issue.  I was under the impression that if I wrote a post 6 months ago and updated its categories that it would be placed into the feed again.  That's not the case, which means my Update Categories function isn't as critical as I thought.  Still, its nice to have, and besides, any hour spent working with .Text source is a hour well spent!

 

Comments (1) | Post RSS RSS comment feed

Posted on 10/8/2004 2:53:00 PM by Dave Burke
Categories:
Tags:

Related posts

Comments (1) -


Powered by BlogEngine.NET 2.0.0.36
Theme by Dave Burke