Doing Things the Long Way
I wanted to do a little change to some code I'd written for CS yesterday. For both the Gaptcha control and my in-line file uploader I'm uploading a file and saving somewhere within the current user's blog. I've been constructing the save locations (and hence the URL to the saved file) in a sorta roundabout way, relying on using the Weblog.Url property to get the url to the root of the blog, and constructing the rest myself.
I knew there was a better way, but hadn't found the time to research I - but now I had it and needed to do some learnin'.
Sometime in the last couple of weeks I remembered reading a blog post from someone about dealing with urls in Community Server. I forgot to bookmark but I knew I'd want to read it sometime, and that time was yesterday. I looked and looked and couldn't find the damn post anywhere!
So what do you do when you need to know something about Community Server in a hurry? Contact the friendly telligent helper-monkey Dave Burke! I found him on messenger and asked if he could remember seeing it - I was pretty sure I'd seen a reference to it in the Community Server Daily News, but I couldn't see it there either.
After a little bit of banter convincing him that this was life-or-death important, and that I really didn't care that it was after 1AM in the states at this stage (afternoon here in Oz) he was willing to help. And he set to with vim and vigour all manner of useful information that I didn't see immediately because I was rudely interrupted by someone who wanted to talk to me (IN PERSON!) it ends up that not only did he remember it, but it was him that wrote it :) So I got my help and he was allowed to go to bed (ok, so he went to bed while I was busy doing this talking thing, but he emailed it all to me just in case messenger died).
Thanks Dave. I knew you were useful for something. And in this case, you were useful big time :)
So having read that post, things were easy. Add a method to the BlogUrls object, register a new pattern in the siteurls.config file, and now I just call BlogUrls.Gaptcha(CurrentWeblog, desiredFileName) and it returns to me the url to the file in the Gaptcha images directory. Sweet! I think now to get the url to the file, and then save the uploaded file to that location what was around 40-50 lines of code has become ten, and is much less error-prone.
The moral of the story? Be nice to your monkey, or it'll spank you :)
You rock, Mr Helper-Monkey! Will you be my valentine?