我只想能够按一个按钮并获取要下载的 xmldocument 文件。
我已经尝试了很多事情,例如:
XmlDocument doc As XmlDocument() = //Method that gets a xmldocument
Response.Clear()
this.Response.ContentType = "text/xml"
xmldoc.Save(this.Response.OutputStream)
和
Dim xmldocument As XmlDocument = //Method that gets a xmldocument
Using stream As MemoryStream = New MemoryStream()
Dim xmlWriter As XmlTextWriter = New XmlTextWriter(stream, System.Text.Encoding.ASCII)
xmldocument.WriteTo(xmlWriter)
xmlWriter.Flush()
Dim byteArray As Byte() = stream.ToArray()
Response.Clear()
Response.AppendHeader("Content-Disposition", "filename=MyExportedFile.xml")
Response.AppendHeader("Content-Length", byteArray.Length.ToString())
Response.ContentType = "application/octet-stream"
Response.BinaryWrite(byteArray)
xmlWriter.Close()
End Using
没有任何效果,我是否忘记了一些明显的事情?因为没有任何效果,所以加载了 xmldocument 一切似乎都很好,但文件从不下载,“响应”完全没有任何作用!
Csharp 或 VB.NET 中的答案会有所帮助