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

CSModule to set Extended Attributes on Weblog Creation

Someone asked today on CS Forums how to set the default blog Feedback Notification to "All Feedback" when a new blog is created.  The default is "none," and there isn't an option to set that property when creating a new blog in Community Server.  To me this belongs where it already is, in My Blog->Settings->Advanced Post Settings->Email Feedback->(none, All Feedback, or All Comments) and set by the blog owner.

But it was an interesting question and I couldn't let it go, so I spent tonight's Geek Session on figuring out how to best accomplish it.  The most interesting source focus of the night to me was working with Extended Attributes.  The function of the ExtendedAttributes Class, as the class summary reads, is to "Provide a standard implementation for simple extended data storage."  Core CS objects like Weblog, Gallery, Forum and Files inherit from the CS.Components.Section class (here's a sample Section object), and Section inherits from Components.ExtendedAttributes.

ExtendedAttributes are a serialized NameValueCollection and accessed with standard Gets, Sets, and other methods found in the ExtendedAttributes class.  We can retrieve attributes specific to the Weblog class, for instance, by calling

section.GetExtendedAttribute("SomeAttributeName");

You'll find examples of serialized Extended Attributes in the PropertyNames and PropertyValues fields of the cs_Sections SQL table.  Here's an example of Keys and Values:

data.Keys:

"SectionOwners:S:0:4:EnableAggBugs:S:4:4:IsCommunityAggregated:S:8:4:aboutTitle:S:12:17:"

data.Values:

"JackTrueTrueAbout Jack's Blog"


Extended Attributes are a beautiful thing, really.

Back to the issue at hand, which is how to set the default blog Feedback Notification property to "All Feedback" when a new blog is created.  This Weblog property is (you guessed it) accessible as an extended attribute in the Section object, but it isn't set when a blog is created, relying on the default "none" (or FeedbackNotificationType.None actually) when needed elsewhere to set the dropdown on the My Blogs->Advanced Post Settings form, for instance.

You may be wondering why I didn't set the WebLog.FeedbackNotificationType to "All Feedback" as the default and be done with it?  Well, that wouldn't have been any fun at all, so don't ask me about it.  What I did instead was really cool, created a CSModule to hook into the PreSectionUpdate Global Event, then set the FeedbackNotificationType extended attribute in section before it was passed to the CommonDataProvider, at which point the weblog was created and the feedbackNotificationType now added.

Here's the custom event method in the CSModule:

private void csa_PreSectionUpdate(Section section, CSEventArgs e)
{
    if (section.ApplicationType == ApplicationType.Weblog)
        section.SetExtendedAttribute("feedbackNotificationType", "1");
}


This CSModule can be modified to update other WebLog (or Forum or Gallery or File) extended attributes on creation as well.  CSModules and Extended Attributes.  Mmmmmm-boy!

Available here:  DaveBurke.CS.SectionModule.zip.


[tags: Community Server, Extended Attributes]

Comments (10) | Post RSS RSS comment feed

Posted on 6/27/2006 8:12:00 PM by Dave Burke
Categories: Community Server
Tags:

Related posts

Comments (10) -

6/28/2006 2:44:23 AM Permalink

ExtendedAttributes are great, but how can I prompt the user with textboxes to enter these new values?
Simo

Simone |

6/28/2006 6:11:33 AM Permalink

Hey, Simone.  Rich Mercer recently wrote a great piece on just that.

http://richmercer.com/archive/2006/05/27/94.aspx

daveburke |

6/28/2006 6:31:33 AM Permalink

Thank you Dave, I already saw itbut it doesn't explain how to render a new textbox in the user registration form
Do I've to modify the core CS ascx files to do this?

Simone |

6/28/2006 6:41:40 AM Permalink

Ah, you're right, Simone.  Rich didn't show the mod change itself.  You'd add those fields most likely to the user sign-up form at \user\CreateUser.aspx and the sourcebehind in CS.Controls.CreateUser.cs.

daveburke |

6/28/2006 9:46:20 AM Permalink

So I need to hack the "offical" code... isn't it?

Simone |

6/29/2006 12:19:15 AM Permalink

The only change I'd recommend is to also add a check on the ObjectState (verifying that the section is being created). Otherwise every time a blog is updated, this event would fire and the ONLY option would be All Feedback. Smile

Something like this:
if ((section.ApplicationType == ApplicationType.Weblog) && (e.State == ObjectState.Create))
        section.SetExtendedAttribute("feedbackNotificationType", "1");

Jose Lema |

6/29/2006 6:52:28 AM Permalink

Ahhh, Jose.  Thank you!  I just added it now.

daveburke |

6/30/2006 3:17:31 AM Permalink

Simone - I just posted about how to use CS's ExtendedUserData feature to accomplish custom registration/profiles without "hacking the code".

Jose Lema |

2/6/2007 11:04:49 AM Permalink

Hey Dave,

I have been looking for direction on how to create a page that allows a user to add a public forum to the cs_Sections table.  I have tried to alter the SectionEdit control in the Control Panel and I have also tried just using the cs_Section_CreateUpdateDelete stored procedure but am having issues getting anything to insert properly.  Do you have any code samples around this that might give me better direction?  This is the last piece for me to finish my site and it is giving me an ulcer. Wink

Thanks,

Brent

Brent |

2/6/2007 11:20:58 AM Permalink

Hi, Brent!  The code to create a forum programmatically is found in this ScottW post.  Hope it does the trick for you.

communityserver.org/.../ShowThread.aspx#551704

daveburke |

Pingbacks and trackbacks (2)+


Powered by BlogEngine.NET 2.0.0.36
Theme by Dave Burke