Click here to Skip to main content
14,302,993 members


Rate this:
3.00 (2 votes)
Please Sign up or sign in to vote.
3.00 (2 votes)
16 Nov 2004
An XML Viewer that displays data, images and video files (and plays them).


This is my first CodeProject article. All comments will be greatly appreciated.

I came up with the idea of developing this control for the fact that every time I had to put an image that was in a DataSet, in a DataList control or any other, I had to go through all the effort that it takes to do so. This control is very simple to use. You put a physical path or URL of an XML file that you want to display, and the table in it you want to use.

It actually uses a DataSet object to load the data, so you have to specify which table in the DataSet you want to use. During runtime, you can change the URL or physical address of the XML file as the name of the table. The control formats all HTTP and FTP addresses to their links, puts all the tags for the image files in JPG, GIF, BMP, PNG, etc. formats. It also displays the Windows Media Player for video files.

For example, if URL: has some XML file in its root folder or any other folder, it displays all the data, images and video files that the file links to, even if the images and videos are contained in that URL. If the XML file is contained in the root or any folder of your web application, you use a physical address taking in consideration the links to those images and/or videos.

Here's some snippet of the Render method of the control.

Here, we start loading the XML in the DataSet and start drawing the control.

protected override void Render(HtmlTextWriter output)

   control_Width = this.Width;
   if (_datasource != null)
    ds = new DataSet();
     if (ds.Tables[TableName].Rows.Count > 0)
      /*If the ShowTableHeader is true we draw a div control.
       *theres a slight bug in the width of the div, so if you
       * fix it send it back pls.
      if (ShowTableHeader)
       output.AddStyleAttribute("BACKGROUND-COLOR", HeaderBackColor.Name);
       output.AddStyleAttribute("BORDER-RIGHT", BorderColor.Name + " " + 
              BorderWidth.Value.ToString()+"px "+BorderStyle);
       output.AddStyleAttribute("BORDER-TOP", BorderColor.Name + " " + 
              BorderWidth.Value.ToString()+"px "+BorderStyle);
       output.AddStyleAttribute("BORDER-LEFT", BorderColor.Name + " " + 
              BorderWidth.Value.ToString()+"px "+BorderStyle);
       output.AddStyleAttribute("BORDER-BOTTOM", BorderColor.Name + " " + 
              BorderWidth.Value.ToString()+"px "+BorderStyle);


This is some image of the control in design time:

Image 1

This is another code snippet that shows how I format the URLs, email address, videos and images for their processing.

foreach(DataRow myRow in ds.Tables[TableName].Rows)
    output.Indent = 2;
    output.WriteAttribute("bordercolor", this.InnerBorderColor.Name);

    foreach(DataColumn myColumn in ds.Tables[TableName].Columns)
        string cellValue = myRow[myColumn].ToString();

        /*Here we put the www, ftp and email addresses
         *their respective links.
        if (cellValue.ToLower().StartsWith("http:")||
            cellValue = "<a target='_blank' href='"+cellValue+"'>"+cellValue+"</a>";

        foreach(char str in cellValue)
            if (str == '@')
                cellValue = "<a href='mailto:"+cellValue+"'>"+cellValue+"</a>";

        output.Indent = 4;

If the XML file you are using is in your local disk, it automatically displays all the images.

This is some image of the control during runtime:

Image 2


There're still many things that you could put better in this control, like using thumbnails instead of the images being displayed, so it is ugly in some occasions. Well, this is my first article so I expect to not disappoint many of you.

Next time, I expect to increase my knowledge a little bit. Thanks in advance, and all comments are welcomed.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Alexander German
Web Developer
Spain Spain
I have been programming for a few years now, like since 1996. Currently working as freelance.

C#.NET MCP. Works with tools such as Delphi, C#.NET, VB.NET, ASP.NET, ADO.NET, XML, java, j2me, Oracle, mySQL, and Sql Server, etc, etc. Open to everything.

Comments and Discussions

Generalplease can I see a demo .exe Pin
maroq30-May-07 3:06
membermaroq30-May-07 3:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Posted 16 Nov 2004


21 bookmarked