PublicActionResult Showlocalizedxml (intID) {stringOrdername =""; stringXMLString = GetXmlStream (ID, outordername); Viewbag.xml=xmlstring; XmlDocument Doc=NewXmlDocument (); Doc. Createcomment (xmlstring); byte[] Array =Encoding.UTF8.GetBytes (xmlstring); //array = Unicodeencoding.convert (Encoding.UTF8, Encoding.unicode, array);MemoryStream stream =NewMemoryStream (array); Response.Cache.SetCacheability (Httpcacheability.nocache); Response.ContentType="Application/octet-stream"; Response.appendheader ("content-disposition","attachment; Filename="+ordername+". XML");//filename to what format, it will download what format file Response.appendheader ("Content-length",""+Stream. Length); byte[] BTS =New byte[Stream. Length]; Stream. Seek (0, Seekorigin.begin); Stream. Read (BTS,0, (int) stream. Length); Response.OutputStream.Write (BTS,0, BTS. Length); returnView (); }
Download files via stream stream