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

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -