Path.GetTempFileName() guarantees that you will get an available name, it does actually go ahead and create the file so it is guaranteed to be yours when you use it. If you strip the extension off and substitute your own you may end up overwriting an existing file. Not a smart thing to do.

In my case, I just really want the filename. Whether or not I change the extension, that file is mine to do with what I will. Also, since it's not in the same folder as the originating file, it can be the exact same name, extension and all, and it will still be a different file that what was generated by the framework. I should take care of file cleanup, and that zero byte file is still in the temp directory...

Be aware the GetTempFileName() actually creates a zero byte file in the temp folder. Your code will leave the temp file behind in the temp folder. If you use that a lot, you will end up with a lot of files in the temp folder.

true! So, maybe I was a little quick to post about this one, but it was one of those things that struck me as particularly useful. If you just want a temporary filename, and want to clean up the file that is created by GetTempFileName(), perhaps this will work a little better:

string GetTempFileName(){
	string filename = Path.GetTempFileName();


	return Path.GetFileNameWithoutExtension(filename);

Okay y' it to shreds :) If I've missed something else obvious, call me out. Or, if you have a preferred method of generating temporary file names, show the way.

If you need to generate temporary / semi-unique filenames, here is a little snippet that uses the framework:

using System.IO;

string GetTempFileName(){
	return Path.GetFileNameWithoutExtension(Path.GetTempFileName());

As the name implies, this will return the temporary name of a file without the extension, so it's up to you to add whatever filetype you may be trying to create. For example, let's say I wanted to generate a .gif:

string GetTempGifFileName(){
	return string.Format("{0}.{1}", GetTempFileName(), "gif");

I had overlooked this little piece of functionality because the component that I was using generated filenames with GUIDs, so I never really worried about it. Way to make my life easier, .netfx :)

[ Currently Playing : Mississippi Queen - Ozzy Osbourne - Under Cover (4:11) ]

Using Yield in Practice
The moral of the story is STOP thinking so hard about it, just use "yield return" the next piece of data in the list.  When using the yield statment GetEnumerator's job is to answer foreach's question - "what's my next item please".  Walk all the items in your collection and yield return what you want.  Don't worry about remembering where you were - that's all part of the generated statemachine goo - it will stop and start the function you write as it pleases in it's MoveNext implementation or whatever (cause we dont really care - we're not suppposed to be thinking, remember?) .  =)

[Via jfo's coding]

I'll admit, I haven't thought a whole lot about yield because, well, I couldn't find anything that described what it did in terms I could understand. I just kept thinking "oh, cool, another new feature in .net 2.0 that I'll get to learn by the time 3.0 comes out" and moved on to the next task.

Thinking about it as kind of a "macro" (similar to what a using(){} block does) lets it gel a little better.

If you do anything "out of the ordinary" in your UserControl or Form derived classes in Visual Studio 2005, let me introduce you to a little snippet that will probably save you lots of headaches:

if ( DesignMode ) return;

or, its equally useful counterpart


Now, the "out of the ordinary" thing I was doing was...hooking up an instance EventHandler using a static property that exposes a Form derived class in an OnLoad override. What? I know, not the clearest situation, and probably one that could use a boatload of refactoring, but it works. In short, if you are having designer problems in Visual Studio 2005, it may be worth it to sit back for a bit and think about what introduced the designer error. Prime candidates are constructors and OnLoad overrides that use static methods for functionality. This code didn't allow me to view the designer of a different form:

public override void OnLoad(EventArgs e){
	AppManager.ConcreteEditorForm.NewPostCreated += new EventHandler(HandleNewPost);

while this one would:

public override void OnLoad(EventArgs e){
	if( DesignMode ) return;

This looks interesting. I thought Mr. "Just finished my last chapter of Beginning AJAX" would have for sure created this as an control...guess I should have read closer the first time ;) Could be useful in PostXING, ifn we ever put some real security innit.

Since there has been so much interest in the SecurePasswordTextBox control (see my previous post and ), I thought I would take the time to iron out the bugs. When I first released it, I performed minimal testing (i.e. about 15 minutes worth) and just thought if anybody else is interested, then I might put some real effort in.

Well since then it was featured in an MSDN webcast by Dan Sellers of Microsoft and I have received almost 300 downloads in a short span of time. So just as a quick courtesy note, it has now been updated to V1.1 and works (AFAIK) 100%. Previous versions didn't handle certain situations property where text in the middle was selected and you typed a character, it would simply append the char and not do a replacement (thanks Nick :-) )

All is now well. Go grab it from here

For those unaware, its a Windows Forms TextBox control that uses the .Net V2 SecureString class to store its contents. Basically, you now have a UI control that allows directly entry into this secure string class and makes it useable from a windows UI perspective. (See my previous post for a full explanation.)

[Via Glavs Blog]

I've got weak regex skillz. I'll admit it.

I don't use them very much, so when I do need to, it's nice to know that regexlib is sitting there, waiting for me to come to it with my regex needs. In particular, there is an online Regular Expression Tester that has helped me to look smarter than I actually am on more than one occasion. Sure, I could use a desktop tool for my regex needs (and sometimes I do), but regexlib has the added bonus of having a collection of user-contributed regular expressions that are super useful when looking for ideas on how to implement a certain regex.

And let's not forget the Cheat Sheet ... regexlib is just chock full of regex goodness.

[ Currently Playing : The First Drop - Rise Against - (2:39) ]

I can't believe nobody called me on this: BackgroundWorker.IsBusy Property

Reflector says it does exactly what I was looking for in a previous post.

Technorati Tags:     

For the adventurous among you, we've decided to release beta 1 of PostXING available for download at ProjectDistributor!

There are a few known issues, but as far as I know there aren't any showstopper bugs. I've been running the development build for quite some time now, and for PostXING v1.1 users, I think this release is a big step up in terms of usability. Since the only working provider at this time is the MetaBlogProvider, the functionality remains basically the same, i.e. you can manage a MetaWeblog enabled weblog using PostXING from your desktop.

If you find any issues, bugs, or you just think something could be done better, head on over to the Gemini issue tracker. To add an issue, click the All Issues link and then Create Issue at the top of the page. If you don't want to get that involved, you can always use the contact form over at to at least get your issue addressed...or you could just let it ride and hope I run into it myself :)

If you're feeling really adventurous and want to hack on PostXING, you can do so by using TortoiseSVN and pointing to All main development is done on the trunk by version. If you don't like how something works, send me a diff. I think I've been pretty receptive to criticism and feature requests (even tho we can't put them all in at once), so the very least that will happen is that you will be able to use a program that you feel works better. Thanks, and enjoy!

[ Currently Playing : Jesus Just Left Chicago - ZZ Top - Tres Hombres (3:31) ]

This is the end result after setting up SubText and importing my old blog (now moved to here). I had created a blogML exporter for cs11 and ran into some initial problems because the version of BlogML I had used was a smidge older (v0.9) and therefore had a different schema. Kinda makes me wish there were a way to clear out all the content and start over like subv2 allows me to.

So why didn't I go with subv2? (Sorry, Darren) The admin interface and WebParts' silly requirement of IE. I basically live in FireFox and although it's been quite some time since I've posted thru the web interface of .text/CS::Blogs, I do need to go in from time to time and make some changes. Plus, since subtext was forked off of .text, I'm already pretty familiar with the interface (and some of the code when necessary). Subv2 is a real nice exploration of all the fun new doohickeys in .net 2.0, and with Darren at the helm you know it's high-quality stuff, but I need something that works for me in the environment I choose to work with. Either way, I've got an install of Subv2 behind the firewall so I could just make that one public and import my shiny new blogML file if need be: I'm keeping a definite eye on it, that's for sure.

[ Currently Playing : Move Me on Down the Line - ZZ Top - Tres Hombres (2:30) ]

More Posts « Previous page - Next page »