HoloXPLOR.Models.HoloTable.DetailModel.GetBytes C# (CSharp) Method

GetBytes() public method

public GetBytes ( ) : Byte[]
return Byte[]
        public Byte[] GetBytes()
        {
            using (MemoryStream ms = new MemoryStream())
            {
                XmlSerializer xs = new XmlSerializer(typeof(Inventory.Player));
                using (XmlTextWriter xw = new XmlTextWriter(ms, Encoding.UTF8))
                {
                    xw.Indentation = 1;
                    xw.IndentChar = ' ';
                    xw.Formatting = Formatting.Indented;

                    xw.WriteWhitespace("");
                    xs.Serialize(xw, this.Player);

                    ms.Seek(0, SeekOrigin.Begin);

                    return ms.ToArray();
                }
            }
        }

Usage Example

Esempio n. 1
0
        public ActionResult Download(String id)
        {
            HoloTableController._lockMap[id] = HoloTableController._lockMap.GetValue(id, new Object());

            lock (HoloTableController._lockMap[id])
            {
                var model = new DetailModel(id);

                var js_handle = this.Request.Cookies["js_handle"];
                var handle = id;

                if (js_handle != null && !String.IsNullOrWhiteSpace(js_handle.Value))
                {
                    handle = js_handle.Value;
                }

                return File(model.GetBytes(), "application/xml", String.Format("{0}.xml", handle));
            }
        }