Scott Hanselman

Speaking at the OCCA - Home Server and Zero Email Bounce

August 29, 2007 Comment on this post [5] Posted in Speaking
Sponsored By

I'll be speaking at the Oregon Computer Consultants Association (OCCA) tonight at 7pm-8:30pm. A no-host dinner starts at 6pm. The meeting is Free and Open to the Public.

Topics

"Join Scott Hanselman for a two part presentation:

First - Let go of the psychic weight of the 10000 emails in your Inbox and enjoy the bliss you can get with "zero email bounce." We'll talk about what that is, and how you can implement it in your daily email workflow, in Outlook, or in Gmail and other clients.

Second - We'll talk about Windows Home Server. Scott's been beta testing WHS for the last 6 months and living with it day to day. We'll see what it offers, if you should build or buy and what it provides over one of the off-the-shelf NAS solutions."

Location

Rheinlander German Restaurant
5035 NE Sandy Blvd
Portland OR 97213  (view map)

If you're in the neighborhood this evening, I hope to see you there!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Hanselman Forums - AspNetForum from JitBit

August 29, 2007 Comment on this post [5] Posted in Reviews
Sponsored By

WindowClippingI wanted to take a second to not only remind folks of the Forums over at http://hanselman.com/forums, but also to recognize AspNetForum from JitBit and what they've done in the last month or so.

in July I started evaluating Forums Software and tried a number of them and installed three.

I ended up picking the most bare-bones one, at the time, AspNetForum. It costs only US$85, which is insanely cheap. I paid it happily. It's not bare-bones now.

It's ridiculously fast. Head over to the Forums and try it out for yourself. It's easy to modify; It took me all of a half-hour to skin and modify the Master Page to make the forums look like this site, including the very-top navigation.

In the last month I've thrown a pile of suggestions at JitBit on ways they could improve the software and nearly every one has been added, cleanly, within a few weeks. I've since upgraded the forums four times, easily.

Here's some of the cool features (many new) since I launched the forums in July:

They've also got an RSS Feed for their Version History, which is a MicroISV Best Practice if ever I saw one.

JitBit doesn't know me from Adam, I'm just a fan. I paid for their product, they've paid me nothing. I just am really happy with the software I selected for the forums. For $85, I'm very happy with my purchase.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

New XML Schema Designer CTP released for Visual Studio 2008

August 29, 2007 Comment on this post [2] Posted in XML
Sponsored By

 A few months ago the XmlTeam teased us with some screenshots and screencasts of a newly redesigned XSD Designer for Visual Studio 2008. It's unclear if this will make it into RTM or if it'll be a quick download/add-in, but regardless today they released CTP1 of the XML Schema Designer (download).

XML Schema Designer

The original schema design surface was more DataSet focused and it would sometimes mess with your Schemas. It was clear (to me at least) that it was schizophrenic to have on designer taking on double duty, especially as folks are making more and more complex Schemas. Here's a books.xsd schema I use for examples, loaded into VS 2008 with the new Schema Explorer on the right.

Also, a tip when writing Xml Schemas in Visual Studio...don't forget to right-click and hit Insert Snippet. The XSD Editor includes a metric butt-load of XSD-specific snippets that are worth using.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Mixing XmlSerializers with XElements and LINQ to XML

August 29, 2007 Comment on this post [0] Posted in Learning .NET | LINQ | Programming | XML | XmlSerializer
Sponsored By

I used to mix and match XmlWriters and XmlSerializers when I had objects that I wanted to serialize in the middle of a larger chunk of XmlWriter-generated XML, like this, where the variable a is typeof(Author).

using (XmlWriter writer = 
        XmlWriter.Create(Response.OutputStream, settings))
{
    //Note the artificial, but useful, indenting
    writer.WriteStartDocument();
        writer.WriteStartElement("bookstore");
            writer.WriteStartElement("book");
                writer.WriteStartAttribute("publicationdate");
                    writer.WriteValue(publicationdate);
                writer.WriteEndAttribute();
                writer.WriteStartAttribute("ISBN");
                    writer.WriteValue(isbn);
                writer.WriteEndAttribute();
                writer.WriteElementString("title", "ASP.NET 2.0");
                writer.WriteStartElement("price");
                    writer.WriteValue(price);
                writer.WriteEndElement(); //price
                XmlSerializer xs = factory.CreateSerializer(typeof(Author));
                xs.Serialize(writer, a);
            writer.WriteEndElement(); //book
        writer.WriteEndElement(); //bookstore
    writer.WriteEndDocument();
}

See how there XmlSerializer just writes directly to the XmlWriter and the object is serialized in the middle of the XmlWriter calls? I found this very useful and used it often.

I wanted to do the same thing with LINQ to XML but was ever so frightened. Earlier I punted and just created the XML myself as an XElement tree. See the author "a" in the middle there?:

        XNamespace ns = "http://example.books.com";
        XDocument books = new XDocument(
            new XElement(ns + "bookstore",
                new XElement(ns + "book",
                    new XAttribute("publicationdate", publicationdate),
                    new XAttribute("ISBN", isbn),
                    new XElement(ns + "title", "ASP.NET 2.0 Book"),
                    new XElement(ns + "price", price),
                    new XElement(ns + "author", 
                        new XElement(ns + "first-name", a.FirstName),
                        new XElement(ns + "last-name", a.LastName)
                        )
                    )
               )
            );

Ion on the XmlTeam explained that the XmlWriter returned by calls to CreateWriter on both XDocument and XElement classes is special. After your done using the XmlWriter and it's Close()d, it will take all the generated XML and Add() it to the parent/owner XDocument or XElement.

So, now I can make an extension method and add my SerializeAsXElement method to XmlSerializer:

   static class XmlSerializerExtension {
       public static XElement SerializeAsXElement(this XmlSerializer xs, object o) {
           XDocument d = new XDocument();
           using (XmlWriter w = d.CreateWriter()) xs.Serialize(w, o);
           XElement e = d.Root;
           e.Remove();
           return e;
       }
   }

Notice the use of using to ensure the XmlWriter is close (Close is called in the Dispose of XmlWriter) and that the root element is removed from the document. Ion explains that "This avoids the cloning of the returned element during any subsequent Add() (eg. functional construction)."

Now, I can use the extension method in the middle of my XElement expression.

        XmlSerializer xs = new XmlSerializer(typeof(Author));
        XDocument books = new XDocument(
            new XElement(ns + "bookstore",
                new XElement(ns + "book",
                    new XAttribute("publicationdate", publicationdate),
                    new XAttribute("ISBN", isbn),
                    new XElement(ns + "title", "ASP.NET 2.0 Book"),
                    new XElement(ns + "price", price),
                    xs.SerializeAsXElement(a)
                    )
               )
            );

And it produces XML identical to the XmlWriter example at the beginning. Big thanks to Ion Vasilian (brilliant moderator of the LINQ Project forums and XmlTeam blogger) for all the help with this question.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Paste XML as XLinq XElement Visual Studio AddIn

August 28, 2007 Comment on this post [3] Posted in Learning .NET | LINQ | Programming | XML
Sponsored By

In the May 2006 CTP of Visual Studio there was a great "Paste XML as XElement" feature that didn't make it into the product. However, seems features can be snuck in included as Samples.

In VB9, you can do really cool things like this with XML literals:

 Dim books = <bookstore xmlns="http://examples.books.com">
                        <book publicationdate=<%= publicationdate %> ISBN=<%= isbn %>>
                            <title>ASP.NET Book</title>
                            <price><%= price %></price>
                            <author>
                                <first-name><%= a.FirstName %></first-name>
                                <last-name><%= a.LastName %></last-name>
                            </author>
                        </book>
                    </bookstore>

In C# it's more of a hassle, because you have to build the XElement tree yourself:

  XNamespace ns = "http://example.books.com";
        XDocument books = new XDocument(
            new XElement(ns + "bookstore",
                new XElement(ns + "book",
                    new XAttribute("publicationdate", publicationdate),
                    new XAttribute("ISBN", isbn),
                    new XElement(ns + "title", "ASP.NET Book"),
                    new XElement(ns + "price", price),
                    new XElement(ns + "author", 
                        new XElement(ns + "first-name", a.FirstName),
                        new XElement(ns + "last-name", a.LastName)
                        )
                    )
               )
            );

However, the Paste XML as XLinq/XElement Addin Sample in Visual Studio 2008 adds a new menu item to the Edit Menu.

PasteXmlAsXLinq

From Visual Studio 2008 Beta 2, select Help, then Samples. Click on Visual C# Samples, Linq Samples, then PasteXmlAsXLinq. At this point, you're actually inside a Zip file, so you might want to backup before you drag them out, or just unzip the whole "C:\Program Files (x86)\Microsoft Visual Studio 9.0\Samples\1033\CSharpSamples.zip" to a development directory. 

imageDrop out to a Visual Studio 2008 command prompt and run MSBuild PasteXmlAsLinq.csproj (or compile it inside of VS). Take the XmlToXLinq.dll and XmlToXLinq.AddIn and put them in one of the addin folders. Usually this is in something like c:\Users\Scott\Documents\Visual Studio 2008, but I like my things tidy, so I made a separate folder in my Dev Folder just for AddIns. From VS, to Tools|Options|Environment|AddIns and add a new folder if you like and copy those two files in there.

Restart VS and you'll get this new option. It'll take whatever XML you have in the clipboard and paste it as an XElement declaration.

It's not XML Literals for C#, but it does make life easier.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.