8.29.2009

XML Web Part

It’s not superior in any way to the SharePoint web part, but I don’t have the source for the SharePoint web part just laying around either.  The code uses the XslCompiledTransform class to transform the xml provided.

 

 

using System.Web.UI.WebControls.WebParts;

using System.Xml.Xsl;

using System.Xml;

using System.IO;

using System;

using System.ComponentModel;

using System.Diagnostics;

 

namespace IdahoWebParts

{

    public class XMLWebPart : WebPart

    {

 

 

        [Personalizable, Browsable(true),WebBrowsable(true),Description("Url of Source XML Document")]

        public string SourceURL

        {

            get

            {

                return (string)ViewState["XmlURL"];

            }

 

            set

            {

                ViewState["XmlURL"] = value;

            }

        }

 

        [Personalizable, Browsable(true),WebBrowsable(true),Description("XML to transform")]

        public string Document

        {

            get

            {

                return (string)ViewState["XmlDocument"];

            }

 

            set

            {

                ViewState["XmlDocument"] = value;

            }

        }

 

        [Personalizable, Browsable(true),WebBrowsable(true),Description("URL of StyleSheet")]

        public string StyleSheetURL

        {

            get

            {

                return (string)ViewState["XsltURL"];

            }

 

            set

            {

                ViewState["XsltURL"] = value;

            }

        }

 

        [Personalizable, Browsable(true),WebBrowsable(true),Description("XSLT used to transform XML")]

        public string StyleSheet

        {

            get

            {

                return (string)ViewState["XsltDocument"];

            }

 

            set

            {

                ViewState["XsltDocument"] = value;

            }

        }

 

        protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)

        {

            try

            {

                // get the style sheet

                string transformDocument = (!string.IsNullOrEmpty(StyleSheetURL)) ? Utility.GetWebTextFile(Page.ResolveUrl(StyleSheetURL)) : StyleSheet;

 

                // get the xml

                string xmlDoc = (!string.IsNullOrEmpty(SourceURL)) ? Utility.GetWebTextFile(Page.ResolveUrl(SourceURL)) : Document;

 

 

                writer.Write(string.Format("<div id={0}>", UniqueID));

                // if we have a style sheet use it to transform the xml

                if (!string.IsNullOrEmpty(transformDocument) && !string.IsNullOrEmpty(xmlDoc))

                {

                    XslCompiledTransform transform = new XslCompiledTransform();

                    transform.Load(XmlReader.Create(new StringReader(transformDocument)));

                    transform.Transform(XmlReader.Create(new StringReader(xmlDoc)), XmlWriter.Create(writer));

                }

 

                else if (!string.IsNullOrEmpty(xmlDoc))

                {

                    writer.Write(xmlDoc);

                }

 

                writer.Write("</div>");

            }

 

            catch (System.Xml.XmlException)

            {

 

                writer.Write("XML error");

            }

 

            catch (Exception exception)

            {

                writer.Write("Error");

                Debug.WriteLine(exception.ToString());

            }

        }

    }

}

8.21.2009

Test...

Is this thing on? I am a developer working for General Dynamics IT as a contractor for the US Army in Iraq. When I come up with something useful that I need to record, I will post it here. This blog has had other subject matter in the past, but now it is about asp.net development.

9.08.2006

White Party and Flaunt

Anyone who has the opportunity should walk in a fashion show. Flaunt was a great experience. Al Wilson's Birthday party during Club Vinyl's White Party in Denver was pretty cool too.

8.28.2006

Fabric

Look for my upcoming role in the independent movie "Fabric", a docu-drama about gay and lesbian issues. It will be showing in film festivals around the country.

Flaunt!

I am going to be walking in the Flaunt Fashion show in Colorado Springs presented by Veda Salsons and Idoru Clothing on September 7th. Come Check it out! The proceeds go to benefit Futureself.

Fabric

Look for my role in Fabric, and independent film directed by John Marquez and produced by Marcorp Productions, at select film festivals around the country.

6.16.2006

My Echo Chamber

By neglecting my blog for so much time I have effectively created an echo chamber. No matter. Everybody (I suppose I should say "nobody") wish me luck on the written suitability exam for the Denver Fire Department.