asp.net - Download XML string to text file c# -
i have xml string , need download string .xml file. working on asp.net web application. following code.
protected void btndownloadxml_click(object sender, eventargs e) { try { string xmltext = divlogresults.innertext; xmldocument doc = new xmldocument(); doc.loadxml(xmltext); doc.save("myfilename.xml"); system.web.httpresponse response = system.web.httpcontext.current.response; response.clearcontent(); response.clear(); response.contenttype = "text/xml"; response.addheader("content-disposition", "attachment; filename=" + doc.name + ";"); response.flush(); response.end(); } catch(exception ex) { throw ex; } }
but getting empty xml text on download named #document.xml. doing wrong.
think confusing code. following code did wanted.
httpresponse response = httpcontext.current.response; string xmlstring = divlogresults.innertext; string filename = "exportedform.xml"; response.statuscode = 200; response.addheader("content-disposition", "attachment; filename=" + filename); response.addheader("content-transfer-encoding", "binary"); //response.addheader("content-length", _buffer.length.tostring()); response.contenttype = "application-download"; response.write(xmlstring);
Comments
Post a Comment