Return file download from byte[]

前端 未结 3 1817
灰色年华
灰色年华 2021-01-21 05:20

This code

string xml = XmlHelper.ToXml(queryTemplate);

byte[] xmlb = StringHelper.GetBytes(xml);

var cd = new System.Net.Mime.ContentDisposition
{
    // for e         


        
3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-21 05:39

    Something like this would work:

    try
    {
        Response.ContentType = "application/octet-stream"; 
        Response.AddHeader( "Content-Disposition", "attachment; filename=" + filename ); 
        Response.OutputStream.Write(xmlb, 0, xmlb.Length); 
        Response.Flush(); 
    } 
    catch(Exception ex) 
    {
        // An error occurred.. 
    }
    

提交回复
热议问题