客户端:点击下载button:
function ExportTempDef()
{
var hfTId = $('hfTemDefId');
hfTId.value = "Export_"+currentTempDefID;
document.forms[0].submit();
hfTId.value = "";
}
服务器端:
page_load 事件:
if (this.hfTemDefId.Value.StartsWith("Export", true, null)) // Export Form Template.
{
string[] strArr = this.hfTemDefId.Value.Split('_');
string tempDefID = strArr[1];
try
{
using (CWrapConn conn = new CWrapConn(System.Configuration.ConfigurationManager.ConnectionStrings["DBString"].ConnectionString))
{
long lTempDefID = Convert.ToInt64(tempDefID);
XmlDocument xmlDoc = TemplateDB.ExportTemplate(lTempDefID);
if (xmlDoc != null)
{
string strExportName = GetExportTempName(lTempDefID);
Response.ContentType = "application/ftf";
Response.AddHeader("Content-disposition", "attachment; filename=" + strExportName + ".ftf");
StringBuilder sb = new StringBuilder();
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.IndentChars = (" ");
settings.OmitXmlDeclaration = false;
//XmlWriter xw = XmlWriter.Create(Response.OutputStream);
XmlWriter xw = XmlWriter.Create(sb, settings);
xmlDoc.WriteTo(xw);
xw.Flush();
StreamWriter sw = new StreamWriter(Response.OutputStream);
//sw.Write(xmlDoc.OuterXml);
sw.Write(sb.ToString());
sw.Flush();
Response.End();
}
}
return;
}
}catch (Exception ex)
{
if (ex is ThreadAbortException)
{
throw ex;
}
}
}