This project is read-only.

Custom data.xml from LINQ

Nov 4, 2010 at 11:04 PM

I've read all the other post's and fought with this easy solution for a while - but

here's what I did -

First - set up your linq to sql DBML file

(build the project so you see it)


create an aspx page called dynamic_xml.aspx

delete everything but the <%@ Page line

In the code behind

Public Class dynamic_XML
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim xml As New StringBuilder
        xml.AppendLine("<?xml version='1.0' encoding='utf-8' ?>")
        xml.AppendLine("<data startalbumindex='0'  transition='CrossFadeTransition'>")
        xml.AppendLine("<album> ")
        Dim db As New inventoryDataContext()
        Dim results = db.getstockimages(Request.QueryString("id")).ToList
For Each imagepath As Object In results Dim myimagepath As String = "uploadedimages/" & imagepath.imagepath xml.AppendLine("<slide") xml.AppendLine(String.Format("source = '{0}'", myimagepath)) xml.AppendLine("/>") Next xml.AppendLine("</album>") xml.AppendLine("</data>") Try Response.ContentType = "text/xml" Response.Write(xml.ToString) Catch ex As Exception End Try End Sub End Class

that is the complete code behind file!

my dbml is called inventory.dbml -

getstockimages is a sql sproc and accepts @id to return me the



and here is how I called it on the display page


        height="650"> <param name="background" value="white" />
        <param name="source" value="Vertigo.SlideShow.xap" />
        <param name="Windowless" value="true" />
<param name="initParams" value="ConfigurationProvider=XmlConfigurationProvider;Path=configuration.xml,DataProvider=XmlDataProvider;Path=dynamic_XML.aspx?id=<%= request.querystring("id") %>" />


it's that simple -- no need for multiple files and hundres of lines of code to follow.

Let me know how that works for you.