예제 #1
0
        void btnExport_Click(object sender, EventArgs e)
        {
            if (CurrentForm != null)
            {
                string fileName = string.Concat("_", CurrentForm.Name, DateTime.UtcNow.ToString("yyyy_MM_dd___HH_mm_ss"), ".csv");

                var csv = new SNC.File(CurrentForm);
                csv.Name = fileName;

                csv.Binary             = new BinaryData();
                csv.Binary.FileName    = fileName;
                csv.Binary.ContentType = "application/vnd.ms-excel";

                string text = GetCSV(CurrentForm);

                MemoryStream stream = new MemoryStream();
                StreamWriter writer = new StreamWriter(stream, Encoding.GetEncoding("windows-1250"));
                writer.Write(text);
                writer.Flush();

                csv.Binary.SetStream(stream);

                csv.Save();

                //HttpContext.Current.Response.ClearHeaders();
                //HttpContext.Current.Response.Clear();
                //HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + csv.Name);
                //HttpContext.Current.Response.AddHeader("Content-Length", csv.Binary.Size.ToString());
                //HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
                //HttpContext.Current.Response.Write(new BinaryReader(csv.Binary.GetStream()).ReadString());
                //HttpContext.Current.Response.End();

                (this.Parent as SingleContentView).OnUserAction(sender, "cancel", "Click");
            }
        }
예제 #2
0
        private void CreateOrModifyCacheFile(BinaryData cacheBinary, bool compress)
        {
            SN.File      f           = null;
            MemoryStream cacheStream = new MemoryStream();

            if (compress)
            {
                GZipOutputStream gzipStream = new GZipOutputStream(cacheStream);
                byte[]           buff       = Encoding.ASCII.GetBytes(this._content.ToCharArray());
                gzipStream.Write(buff, 0, buff.Length);
                gzipStream.Flush();
                gzipStream.Close();

                // set compressed binary
                byte[] compressedData = cacheStream.ToArray();
                cacheBinary.SetStream(new MemoryStream(compressedData));
            }
            else
            {
                cacheBinary.SetStream(Tools.GetStreamFromString(_content));
            }

            // gets cache file or creates a new one, the new stream will be saved in both cases
            if (!Node.Exists(FullCacheFilePath))
            {
                f      = SN.File.CreateByBinary(this.CacheFolder, cacheBinary);
                f.Name = _cacheFile;
            }
            else
            {
                f        = Node.Load <SN.File>(this.FullCacheFilePath);
                f.Binary = cacheBinary;
            }
            f.Save();
        }