用户单击按钮后,我想要下载文件.我已经尝试了以下似乎可以工作,但不是没有抛出一个不可接受的异常(ThreadAbort).
System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.ClearContent();
response.Clear();
response.ContentType = "text/plain";
response.AddHeader("Content-Disposition", "attachment; filename=" + fileName + ";");
response.TransmitFile(Server.MapPath("FileDownload.csv"));
response.Flush();
response.End();
Run Code Online (Sandbox Code Playgroud) 我正在尝试将XML文件反序列化为对象数组,但我收到的是空对象.我的问题看起来类似于:如何将xml反序列化为对象数组?但我似乎无法创建一个继承IXmlSerializable的类.也就是说,我不认为这种方法是必要的.
难道我做错了什么?
文件对象
[XmlType("file")]
public class File
{
[XmlElement("id")]
public string Id { get; set; }
[XmlElement("company_name")]
public string Company_Name { get; set; }
[XmlElement("docs")]
public HashSet<doc> Docs { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
Doc对象
[XmlType("doc")]
public class Doc
{
[XmlElement("valA")]
public string ValA { get; set; }
[XmlElement("valB")]
public string ValB { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
XML
<?xml version="1.0" encoding="UTF-8"?>
<files>
<file>
<id>12345</id>
<company_name>Apple</company_name>
<docs>
<doc>
<valA>Info</valA>
<valB>More Info</valB>
</doc>
</docs>
</file>
<file>
<id>12345</id>
<company_name>Microsoft</company_name>
<docs>
<doc>
<valA>Even …Run Code Online (Sandbox Code Playgroud)