views:

23

answers:

1

I'm playing with VB XML literals for returning and Excel XML file. the problem is that the first line containing <?xml version="1.0"?> does not make to the download.

Here is the code:

Public Class ReservasController
Function Test()
    Response.Clear()
    Response.AddHeader("Content-Disposition", "attachment; filename=test.xml")
    Response.ContentType = "application/vnd.ms-excel"
    Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8")
    Response.Write(GetXML())
    ''//This works:
    ''//Response.Write("<?xml version=""1.0""?>" + GetXML().ToString())
    Response.End()
    Return Nothing
End Function

The GetXML method is very simple:

Private Function GetXML()
    Return <?xml version="1.0"?>
           <?mso-application progid="Excel.Sheet"?>
           <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
               xmlns:o="urn:schemas-microsoft-com:office:office"
               xmlns:x="urn:schemas-microsoft-com:office:excel"
               xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
               xmlns:html="http://www.w3.org/TR/REC-html40"&gt;
               <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
                   <Author>Bizcacha Excel Generator</Author>
                   <LastAuthor>Bizcacha Excel Generator</LastAuthor>
                   <Created>20100101</Created>
                   <Company>Bizcacha</Company>
                   <Version>1</Version>
               </DocumentProperties>
               <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
               </ExcelWorkbook>
               <Styles>
                   <Style ss:ID="Default" ss:Name="Normal">
                       <Alignment ss:Vertical="Bottom"/>
                       <Borders/>
                       <Font/>
                       <Interior/>
                       <NumberFormat/>
                       <Protection/>
                   </Style>
               </Styles>
               <Worksheet ss:Name="title">
                   <Table x:FullColumns="1" x:FullRows="1" ss:DefaultRowHeight="15">
                       <Column ss:Width="100"/>
                       <Column ss:Width="100"/>
                       <Row ss:AutoFitHeight="0">
                           <Cell ss:StyleID="Default"><Data ss:Type="String">Hello</Data></Cell>
                           <Cell ss:StyleID="Default"><Data ss:Type="String">World</Data></Cell>
                       </Row>
                   </Table>
               </Worksheet>
           </Workbook>
End Function
End Class
A: 
tommieb75
I'm using XML literals. No need to concatenate strings.
Eduardo Molteni