Пример #1
0
        public SPKAttachmentModel GetDocAttachment(int id)
        {
            SPKAttachmentModel att = new SPKAttachmentModel();

            using (TDMDBEntities context = new TDMDBEntities())
            {
                var _qry = context.tb_Attachment.SingleOrDefault(x => x.Id == id);
                if (_qry != null)
                {
                    att.Id             = (Int32)_qry.Id;
                    att.AttachmentName = _qry.AttachmentName;
                    att.Attachment     = _qry.Attachment;
                    att.DocId          = _qry.DocId;
                    att.DocType        = _qry.DocType == null ? 0 : (int)_qry.DocType;
                }
            }

            return(att);
        }
Пример #2
0
        public ActionResult DownloadAttachment(string id)
        {
            System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
            SPKBll _spkbllobj = new SPKBll();

            SPKAttachmentModel _attFile = _spkbllobj.GetDocAttachment(Convert.ToInt32(id));

            Response.ClearContent();
            // adding the headers to file stream
            Response.AddHeader("Content-Disposition", "attachment; filename=" + _attFile.AttachmentName);
            //Streaming out the data(file) from database to client(browser)
            BinaryWriter bw = new BinaryWriter(Response.OutputStream);

            // converting data into bytes
            byte[] file = (byte[])_attFile.Attachment;

            bw.Write(file);
            bw.Close();
            Response.End();
            return(View());
        }