Exemplo n.º 1
0
        protected void gvUploadedFiles_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            decimal document_id = (decimal)e.Keys[0];

            SQMDocumentMgr.Delete(document_id);
            Bind_gvUploadedFiles();
        }
        protected void lbUpload_Click(object sender, EventArgs e)
        {
            string name = "";

            if (flFileUpload.HasFile)
            {
                name = flFileUpload.FileName;

                decimal?display_type = null;
                if (SessionManager.DocumentContext.Scope == "USR")
                {
                    display_type = 15;
                }
                else
                {
                    display_type = Convert.ToDecimal(ddlDisplayType.SelectedValue);
                }

                Stream   stream = flFileUpload.FileContent;
                DOCUMENT d      = SQMDocumentMgr.Add(flFileUpload.FileName, tbFileDescription.Text, display_type, SessionManager.DocumentContext.Scope, SessionManager.DocumentContext.RecordID, stream);
                if (d != null)
                {
                    Bind_gvUploadedFiles();
                    // mt - put the new document and upload status in session so that we can retrieve it (if necessary) from the calling page
                    SessionManager.ReturnObject = d;
                    SessionManager.ReturnStatus = true;
                }
                else
                {
                    SessionManager.ClearReturns();
                }
            }
        }
Exemplo n.º 3
0
        public void SaveFiles()
        {
            string[] descriptions = hfDescriptions.Value.Split('|');

            int i = 0;

            foreach (UploadedFile file in raUpload.UploadedFiles)
            {
                string  description = (i < descriptions.Count()) ? descriptions[i] : "";
                decimal displayType = (file.FileName.ToLower().Contains(".jpeg") || file.FileName.ToLower().Contains(".jpg") ||
                                       file.FileName.ToLower().Contains(".gif") || file.FileName.ToLower().Contains(".png")) ||
                                      file.FileName.ToLower().Contains(".bmp") ? 1 : 0;
                SQMDocumentMgr.AddAttachment(
                    file.FileName,
                    description,
                    displayType,
                    "",
                    SessionManager.DocumentContext.RecordType,
                    SessionManager.DocumentContext.RecordID,
                    SessionManager.DocumentContext.RecordStep,
                    Session.SessionID,
                    file.InputStream
                    );
                i++;
            }

            // Update "display" status of existing files
            foreach (GridDataItem item in rgFiles.Items)
            {
                decimal  attachmentId = Convert.ToDecimal(item.GetDataKeyValue("AttachmentId"));
                CheckBox cb           = (CheckBox)item["DisplayTypeColumn"].FindControl("checkBox");
                decimal  displayType  = (cb.Checked) ? 1 : 0;
                SQMDocumentMgr.UpdateAttachmentDisplayType(attachmentId, displayType);
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                context.Response.Clear();

                if (!String.IsNullOrEmpty(context.Request.QueryString["DOC_ID"]))
                {
                    String  document_id = context.Request.QueryString["DOC_ID"];
                    Decimal doc_id      = decimal.Parse(document_id);
                    string  fileType    = "";
                    String  mime_type   = "";

                    if (!string.IsNullOrEmpty(context.Request.QueryString["DOC"]))
                    {
                        switch (context.Request.QueryString["DOC"])
                        {
                        case "a":     // attachment
                            ATTACHMENT a = SQMDocumentMgr.GetAttachment(doc_id);
                            fileType = Path.GetExtension(a.FILE_NAME);
                            // set this to whatever your format is of the image
                            context.Response.ContentType = fileType;
                            mime_type = SQM.Website.Classes.FileExtensionConverter.ToMIMEType(fileType);
                            context.Response.ContentType = mime_type;
                            //context.Response.AddHeader("content-length", d.DOCUMENT_DATA.Length.ToString());
                            //context.Response.OutputStream.Write(d.DOCUMENT_DATA, 0, d.DOCUMENT_DATA.Length);
                            context.Response.AddHeader("content-length", a.ATTACHMENT_FILE.ATTACHMENT_DATA.Length.ToString());
                            context.Response.OutputStream.Write(a.ATTACHMENT_FILE.ATTACHMENT_DATA, 0, a.ATTACHMENT_FILE.ATTACHMENT_DATA.Length);
                            context.Response.Flush();
                            break;

                        default:     // document
                            DOCUMENT d = SQMDocumentMgr.GetDocument(doc_id);
                            fileType = Path.GetExtension(d.FILE_NAME);
                            // set this to whatever your format is of the image
                            context.Response.ContentType = fileType;
                            mime_type = SQM.Website.Classes.FileExtensionConverter.ToMIMEType(fileType);
                            context.Response.ContentType = mime_type;
                            //context.Response.AddHeader("content-length", d.DOCUMENT_DATA.Length.ToString());
                            //context.Response.OutputStream.Write(d.DOCUMENT_DATA, 0, d.DOCUMENT_DATA.Length);
                            context.Response.AddHeader("content-length", d.DOCUMENT_FILE.DOCUMENT_DATA.Length.ToString());
                            context.Response.OutputStream.Write(d.DOCUMENT_FILE.DOCUMENT_DATA, 0, d.DOCUMENT_FILE.DOCUMENT_DATA.Length);
                            context.Response.Flush();
                            break;
                        }
                    }
                }

                else
                {
                    context.Response.ContentType = "text/html";
                    context.Response.Write("<p>Document not found</p>");
                }
            }
            catch (Exception e)
            {
                //SQMLogger.LogException(e);
            }
        }
        protected void rgFiles_OnEditCommand(object source, GridCommandEventArgs e)
        {
            GridEditableItem item         = (GridEditableItem)e.Item;
            decimal          attachmentId = (decimal)item.GetDataKeyValue("VideoAttachId");
            VIDEO_ATTACHMENT attach       = SQMDocumentMgr.GetVideoAttachment(attachmentId);

            tbText.Text            = attach.DESCRIPTION;
            tbTimestamp.Text       = attach.TITLE;
            hdnVideoAttachId.Value = attachmentId.ToString();
        }
        protected void lbVideoId_OnClick(object sender, EventArgs e)
        {
            LinkButton       lb           = (LinkButton)sender;
            decimal          attachmentId = Convert.ToDecimal(lb.CommandArgument.ToString());
            VIDEO_ATTACHMENT attach       = SQMDocumentMgr.GetVideoAttachment(attachmentId);

            tbText.Text            = attach.DESCRIPTION;
            tbTimestamp.Text       = attach.TITLE;
            hdnVideoAttachId.Value = attachmentId.ToString();
        }
        protected void gvUploadedFiles_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            decimal document_id = (decimal)e.Keys[0];

            SQMDocumentMgr.DeleteAttachment(document_id);
            Bind_gvUploadedFiles();
            // do below to signal the calling page to refresh the attachment list
            SessionManager.ReturnObject = new ATTACHMENT();
            SessionManager.ReturnStatus = true;
        }
Exemplo n.º 8
0
        protected void Bind_gvUploadedFiles()
        {
            pnlDocMgr.Visible = true;
            List <DOCUMENT> files = SQMDocumentMgr.SelectDocList(SessionManager.EffLocation.Company.COMPANY_ID, SessionManager.DocumentContext);

            gvUploadedFiles.DataSource   = files;
            gvUploadedFiles.DataKeyNames = new string[] { "DOCUMENT_ID" };
            gvUploadedFiles.DataBind();
            gvUploadedFiles.Visible = true;
            SetGridViewDisplay(gvUploadedFiles, lblDocsListEmpty, divDocsGVScroll, 20, 0);
        }
        protected void Bind_gvUploadedFiles()
        {
            files = SQMDocumentMgr.SelectAttachmentListByRecord(SessionManager.DocumentContext.RecordType, SessionManager.DocumentContext.RecordID, SessionManager.DocumentContext.RecordStep, Session.SessionID);

            if (files != null && files.Count > 0)
            {
                gvUploadedFiles.DataSource   = files;
                gvUploadedFiles.DataKeyNames = new string[] { "ATTACHMENT_ID" };
                gvUploadedFiles.DataBind();
                gvUploadedFiles.Visible = true;
            }
        }
Exemplo n.º 10
0
        public int BindDocumentSelect(string docScope, int displayType, bool showLabel, bool clearList, string message)
        {
            int status = 0;


            if (displayType > 0)
            {
                SessionManager.DocumentContext = new DocumentScope().CreateNew(SessionManager.PrimaryCompany().COMPANY_ID, docScope, 0, "", 0, "", new decimal[1] {
                    (decimal)displayType
                });
            }
            else
            {
                SessionManager.DocumentContext = new DocumentScope().CreateNew(docScope, 0, "", 0, "");
            }

            List <DOCUMENT> files = SQMDocumentMgr.SelectDocList(SessionManager.PrimaryCompany().COMPANY_ID, SessionManager.DocumentContext);

            if (clearList)
            {
                ddlSelectDocs.Items.Clear();
            }

            foreach (DOCUMENT doc in files)
            {
                RadComboBoxItem item = new RadComboBoxItem(doc.FILE_DESC, doc.DOCUMENT_ID.ToString());
                item.ToolTip = doc.FILE_NAME;
                // item.Font.Size = 10;
                string[] args = doc.FILE_NAME.Split('.');
                if (args.Length > 0)
                {
                    string ext = args[args.Length - 1];
                    item.ImageUrl = "~/images/filetype/icon_" + ext.ToLower() + ".jpg";
                }

                /*
                 * if (++status % 2 == 0)
                 * {
                 *  item.CssClass = "rcbComboItemAlt";
                 * }
                 */
                ddlSelectDocs.Items.Add(item);
            }
            ddlSelectDocs.Font.Size = 10;
            if (!string.IsNullOrEmpty(message))
            {
                ddlSelectDocs.EmptyMessage = message;
            }

            pnlSelectDocument.Visible = true;
            lblSelectDocs.Visible     = showLabel;
            return(status);
        }
Exemplo n.º 11
0
        public void SaveFiles(int recordType, decimal recordId)
        {
            string[] descriptions = hfDescriptions.Value.Split('|');

            int i = 0;

            foreach (UploadedFile file in raVideoUpload.UploadedFiles)
            {
                string  description = (i < descriptions.Count()) ? descriptions[i] : "";
                decimal displayType = (file.FileName.ToLower().Contains(".jpeg") || file.FileName.ToLower().Contains(".jpg") ||
                                       file.FileName.ToLower().Contains(".gif") || file.FileName.ToLower().Contains(".png")) ||
                                      file.FileName.ToLower().Contains(".bmp") ? 1 : 0;
                switch (recordType)
                {
                case (int)MediaAttachmentType.ReleaseForm:
                    SQMDocumentMgr.AddVideoAttachment(
                        file.FileName,
                        description,
                        "",
                        displayType,
                        recordType,
                        recordId,
                        Session.SessionID,
                        file.InputStream
                        );
                    break;

                default:                         // text entries
                    SQMDocumentMgr.AddVideoAttachment(
                        file.FileName,
                        description,
                        "",
                        displayType,
                        recordType,
                        recordId,
                        Session.SessionID,
                        file.InputStream
                        );
                    break;
                }
                i++;
            }

            // Update "display" status of existing files
            foreach (GridDataItem item in rgVideoFiles.Items)
            {
                decimal  attachmentId = Convert.ToDecimal(item.GetDataKeyValue("VideoAttachId"));
                CheckBox cb           = (CheckBox)item["DisplayTypeColumn"].FindControl("checkBox");
                decimal  displayType  = (cb.Checked) ? 1 : 0;
                SQMDocumentMgr.UpdateAttachmentDisplayType(attachmentId, displayType);
            }
        }
Exemplo n.º 12
0
      //public void SaveFilesPreventativeMeasures()
      //{
      //    string[] descriptions;

      //    //if (trAttachDesc.Visible == true)
      //    //	descriptions = tbAttachDesc.Text.Split('|');
      //    //else
      //    //	descriptions = hfDescriptions.Value.Split('|');

      //    if (hfDescriptions.Value.Length > 0)
      //        descriptions = hfDescriptions.Value.Split('|');
      //    else if (tbAttachDesc.Text.Length > 0)
      //        descriptions = tbAttachDesc.Text.Split('|');
      //    else
      //        descriptions = "".Split('|');

      //    int i = 0;
      //    foreach (UploadedFile file in raUpload.UploadedFiles)
      //    {
      //        string description = (i < descriptions.Count()) ? descriptions[i] : "";
      //        decimal displayType = (file.FileName.ToLower().Contains(".jpeg") || file.FileName.ToLower().Contains(".jpg") ||
      //            file.FileName.ToLower().Contains(".gif") || file.FileName.ToLower().Contains(".png")) ||
      //            file.FileName.ToLower().Contains(".bmp") ? 1 : 0;
      //        SQMDocumentMgr.AddAttachment(
      //            file.FileName,
      //            description,
      //            displayType,
      //            "",
      //            SessionManager.DocumentContext.RecordType,
      //            SessionManager.DocumentContext.RecordID,
      //            SessionManager.DocumentContext.RecordStep,
      //            Session.SessionID,
      //            file.InputStream,
      //            (int)Incident_Section.PreventativeMeasuresAttachment
      //            );
      //        i++;
      //    }

      //    // Update "display" status of existing files
      //    foreach (GridDataItem item in rgFiles.Items)
      //    {
      //        decimal attachmentId = Convert.ToDecimal(item.GetDataKeyValue("AttachmentId"));
      //        CheckBox cb = (CheckBox)item["DisplayTypeColumn"].FindControl("checkBox");
      //        decimal displayType = (cb.Checked) ? 1 : 0;
      //        SQMDocumentMgr.UpdateAttachmentDisplayType(attachmentId, displayType);
      //    }
      //}

      protected void rgFiles_OnDeleteCommand(object source, GridCommandEventArgs e)
      {
          GridEditableItem item         = (GridEditableItem)e.Item;
          decimal          attachmentId = (decimal)item.GetDataKeyValue("AttachmentId");
          ATTACHMENT       attach       = SQMDocumentMgr.DeleteAttachment(attachmentId);

          this.GetUploadedFiles(_recordType, _recordId);

          if (OnAttachmentDelete != null && attach != null)
          {
              OnAttachmentDelete(attach);
          }
      }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //SessionManager.DocumentContext = new SQM.Shared.DocumentScope().CreateNew(1, "", staticScope.RecordType, "", staticScope.RecordID, staticScope.RecordStep, new decimal[0] {});
            //SessionManager.DocumentContext.RecordType = staticScope.RecordType;
            //SessionManager.DocumentContext.RecordID = staticScope.RecordID;
            //SessionManager.DocumentContext.RecordStep = staticScope.RecordStep;
            //uclUpload.SaveFiles();
            if (hdnVideoAttachId.Value.ToString().Equals(""))
            {
                SQMDocumentMgr.AddVideoAttachment(
                    "",
                    tbText.Text.ToString(),
                    tbTimestamp.Text.ToString(),
                    0,
                    _recordType,
                    _recordId,
                    Session.SessionID,
                    null
                    );
            }
            else
            {
                decimal videoAttachId = Convert.ToDecimal(hdnVideoAttachId.Value.ToString());
                SQMDocumentMgr.UpdateVideoAttachment(
                    videoAttachId,
                    "",
                    tbText.Text.ToString(),
                    tbTimestamp.Text.ToString(),
                    0,
                    _recordType,
                    _recordId,
                    Session.SessionID,
                    null
                    );
            }

            this.GetUploadedFiles(_recordType, _recordId);
            tbTimestamp.Text       = "";
            tbText.Text            = "";
            hdnVideoAttachId.Value = "";

            //if (AttachmentEvent != null)
            //{
            AttachmentEvent("save");
            //}
        }
Exemplo n.º 14
0
        protected void Bind_gvUploadedFiles()
        {
            files = null;

            switch (SessionManager.DocumentContext.Scope)
            {
            case "USR":
                files = SQMDocumentMgr.SelectDocListByOwner(SessionManager.UserContext.Person.PERSON_ID, 15);
                break;

            default:
                files = SQMDocumentMgr.SelectDocList(SessionManager.EffLocation.Company.COMPANY_ID, SessionManager.DocumentContext);
                break;
            }

            if (files != null && files.Count > 0)
            {
                gvUploadedFiles.DataSource   = files;
                gvUploadedFiles.DataKeyNames = new string[] { "DOCUMENT_ID" };
                gvUploadedFiles.DataBind();
                gvUploadedFiles.Visible = true;
            }
        }
        protected void rgFiles_OnDeleteCommand(object source, GridCommandEventArgs e)
        {
            //Declare variables for manage the conditions for delete the files from all the incident sections.
            string Incident = "uploader";                                           //for incident step.
            string IncidentFinalCorrectiveAction = "uploaderFinalCorrectiveAction"; //for FinalCorrectiveAction step.
            string IncidentPreventativeMeasures  = "uploaderPreventativeMeasures";  // for PreventativeMeasures step.
            string uploaderID = ID;


            GridEditableItem item         = (GridEditableItem)e.Item;
            decimal          attachmentId = (decimal)item.GetDataKeyValue("AttachmentId");
            ATTACHMENT       attach       = SQMDocumentMgr.DeleteAttachment(attachmentId);


            //after delete display attached files according to uploader id.
            if (uploaderID == Incident)
            {
                this.GetUploadedFilesIncidentSection(_recordType, _recordId, "", (int)Incident_Section.IncidentAttachment);
            }
            else if (uploaderID == IncidentFinalCorrectiveAction)
            {
                this.GetUploadedFilesIncidentSection(_recordType, _recordId, "", (int)Incident_Section.FinalCorrectiveAttachment);
            }
            else if (uploaderID == IncidentPreventativeMeasures)
            {
                this.GetUploadedFilesIncidentSection(_recordType, _recordId, "", (int)Incident_Section.PreventativeMeasuresAttachment);
            }
            else
            {
                this.GetUploadedFiles(_recordType, _recordId);
            }

            if (OnAttachmentDelete != null && attach != null)
            {
                OnAttachmentDelete(attach);
            }
        }
Exemplo n.º 16
0
        protected void Bind_gvUploadedFiles()
        {
            DocumentScope docScope = null;

            // get HR company docs
            if (SessionManager.UserContext.HRLocation.IsPrimaryCompany())
            {
                docScope = new DocumentScope().CreateNew(SessionManager.UserContext.HRLocation.Company.COMPANY_ID, "SYS", 0, "", 0, "", 10);
            }
            else if (SessionManager.UserContext.HRLocation.IsSupplierCompany(false))
            {
                docScope = new DocumentScope().CreateNew(SessionManager.UserContext.HRLocation.Company.COMPANY_ID, "SYS", 0, "", 0, "", 11);
            }
            else if (SessionManager.UserContext.HRLocation.IsCustomerCompany(false))
            {
                docScope = new DocumentScope().CreateNew(SessionManager.UserContext.HRLocation.Company.COMPANY_ID, "SYS", 0, "", 0, "", 12);
            }
            docList = SQMDocumentMgr.SelectDocListFromContext(docScope);

            // get working location docs
            docScope = new DocumentScope().CreateNew(SessionManager.UserContext.WorkingLocation.Company.COMPANY_ID, "BLI", 0, "", SessionManager.UserContext.WorkingLocation.Plant.PLANT_ID, "", 0, 15);
            docList.AddRange(SQMDocumentMgr.SelectDocListFromContext(docScope));

            uclDocList.BindRadDocsList(docList);

            // setup for doc upload if enabled for this user
            SessionManager.DocumentContext = new DocumentScope().CreateNew(SessionManager.UserContext.WorkingLocation.Company.COMPANY_ID, "BLI", 0, "", SessionManager.UserContext.WorkingLocation.Plant.PLANT_ID, "", 0);
            lblPostedDocuments.Text        = "";
            foreach (DOCUMENT doc in docList)
            {
                if (doc.DOCUMENT_SCOPE == "BLI" && doc.RECORD_ID == SessionManager.UserContext.WorkingLocation.Plant.PLANT_ID)
                {
                    lblPostedDocuments.Text += (doc.FILE_NAME + ", ");
                }
            }
        }
Exemplo n.º 17
0
        protected void lbUpload_Click(object sender, EventArgs e)
        {
            string name = "";

            if (flFileUpload.HasFile)
            {
                name = flFileUpload.FileName;

                Stream stream = flFileUpload.FileContent;
                // string sessionID = Session.SessionID;
                ATTACHMENT d = SQMDocumentMgr.AddAttachment(flFileUpload.FileName, tbFileDescription.Text, 0, "", SessionManager.DocumentContext.RecordType, SessionManager.DocumentContext.RecordID, SessionManager.DocumentContext.RecordStep, Session.SessionID, stream, 0);//apply 0 for incident attchment.
                if (d != null)
                {
                    Bind_gvUploadedFiles();
                    // mt - put the new document and upload status in session so that we can retrieve it (if necessary) from the calling page
                    SessionManager.ReturnObject = d;
                    SessionManager.ReturnStatus = true;
                }
                else
                {
                    SessionManager.ClearReturns();
                }
            }
        }
Exemplo n.º 18
0
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                context.Response.Clear();

                if (!String.IsNullOrEmpty(context.Request.QueryString["DOC_ID"]))
                {
                    String document_id = context.Request.QueryString["DOC_ID"];
                    String fileName    = "attachment";

                    Decimal doc_id   = decimal.Parse(document_id);
                    string  fileType = "";
                    String  mimeType = "";

                    if (!string.IsNullOrEmpty(context.Request.QueryString["DOC"]))
                    {
                        switch (context.Request.QueryString["DOC"])
                        {
                        case "a":                                 // attachment
                            ATTACHMENT a = SQMDocumentMgr.GetAttachment(doc_id);
                            fileType = Path.GetExtension(a.FILE_NAME);

                            if (!string.IsNullOrEmpty(context.Request.QueryString["FILE_NAME"]))
                            {
                                fileName = context.Request.QueryString["FILE_NAME"];
                            }
                            else
                            {
                                fileName += fileType;
                            }

                            mimeType = SQM.Website.Classes.FileExtensionConverter.ToMIMEType(fileType);
                            context.Response.ContentType = mimeType;
                            //context.Response.BinaryWrite(a.ATTACHMENT_FILE.ATTACHMENT_DATA);

                            // mt  - use below for video streams ?
                            context.Response.AddHeader("content-disposition", "inline; filename=" + fileName);
                            context.Response.AddHeader("content-length", a.ATTACHMENT_FILE.ATTACHMENT_DATA.Length.ToString());
                            context.Response.OutputStream.Write(a.ATTACHMENT_FILE.ATTACHMENT_DATA, 0, a.ATTACHMENT_FILE.ATTACHMENT_DATA.Length);
                            context.Response.Flush();
                            break;

                        case "v":                                 // video
                            VIDEO v = MediaVideoMgr.SelectVideoById(doc_id);

                            // get the file from Azure
                            fileType = Path.GetExtension(v.FILE_NAME);

                            if (!string.IsNullOrEmpty(context.Request.QueryString["FILE_NAME"]))
                            {
                                fileName = context.Request.QueryString["FILE_NAME"];
                            }
                            else
                            {
                                fileName += fileType;
                            }

                            List <SETTINGS> sets               = SQMSettings.SelectSettingsGroup("MEDIA_UPLOAD", "");
                            string          storageContainer   = sets.Find(x => x.SETTING_CD == "STORAGE_CONTAINER").VALUE.ToString();
                            string          storageURL         = sets.Find(x => x.SETTING_CD == "STORAGE_URL").VALUE.ToString();
                            string          storageQueryString = sets.Find(x => x.SETTING_CD == "STORAGE_QUERY").VALUE.ToString();

                            // Retrieve storage account from connection string.
                            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                                CloudConfigurationManager.GetSetting("StorageConnectionString"));

                            // Create the blob client.
                            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

                            // Retrieve reference to a previously created container.
                            CloudBlobContainer container = blobClient.GetContainerReference(storageContainer);

                            // Retrieve reference to a blob named "photo1.jpg".
                            CloudBlockBlob blockBlob = container.GetBlockBlobReference(v.VIDEO_ID + fileType);

                            // Save blob contents to a file.
                            //using (var fileStream = System.IO.File.OpenWrite(@"path\myfile"))
                            //{
                            //	blockBlob.DownloadToStream(fileStream);
                            //}

                            mimeType = SQM.Website.Classes.FileExtensionConverter.ToMIMEType(fileType);
                            context.Response.ContentType = mimeType;

                            byte[] b = new byte[16 * 1024];
                            using (MemoryStream memoryStream = new MemoryStream())
                            {
                                blockBlob.DownloadToStream(memoryStream);
                                //memoryStream.WriteTo(HttpContext.Current.Response.OutputStream);
                                //memoryStream.Close();
                                b = memoryStream.ToArray();
                            }

                            context.Response.AddHeader("content-disposition", "inline; filename=" + fileName);
                            context.Response.AddHeader("content-length", v.FILE_SIZE.ToString());
                            context.Response.BinaryWrite(b);
                            context.Response.Flush();

                            //// the following is the code for finding the file in the database
                            //VIDEO_FILE vf = MediaVideoMgr.SelectVideoFileById(doc_id);

                            //fileType = Path.GetExtension(v.FILE_NAME);

                            //if (!string.IsNullOrEmpty(context.Request.QueryString["FILE_NAME"]))
                            //	fileName = context.Request.QueryString["FILE_NAME"];
                            //else
                            //	fileName += fileType;

                            //mimeType = SQM.Website.Classes.FileExtensionConverter.ToMIMEType(fileType);
                            //context.Response.ContentType = mimeType;

                            //// mt  - use below for video streams ?
                            //context.Response.AddHeader("content-disposition", "inline; filename=" + fileName);
                            //context.Response.AddHeader("content-length", vf.VIDEO_DATA.Length.ToString());
                            ////context.Response.OutputStream.Write(vf.VIDEO_DATA, 0, vf.VIDEO_DATA.Length);
                            //context.Response.BinaryWrite(vf.VIDEO_DATA);

                            //context.Response.Flush();

                            //// the following is the code for finding the file on the server
                            //fileType = Path.GetExtension(v.FILE_NAME);

                            //fileName = context.Server.MapPath(v.FILE_NAME);
                            //System.IO.FileInfo fileInfo = new System.IO.FileInfo(fileName);

                            //try
                            //{
                            //	if (fileInfo.Exists)
                            //	{
                            //		context.Response.Clear();
                            //		context.Response.AddHeader("Content-Disposition", "attachment;filename=\"" + fileInfo.Name + "\"");
                            //		context.Response.AddHeader("Content-Length", fileInfo.Length.ToString());
                            //		context.Response.ContentType = "application/octet-stream";
                            //		context.Response.TransmitFile(fileInfo.FullName);
                            //		context.Response.Flush();
                            //	}
                            //	else
                            //	{
                            //		throw new Exception("File not found");
                            //	}
                            //}
                            //catch (Exception ex)
                            //{
                            //	context.Response.ContentType = "text/plain";
                            //	context.Response.Write(ex.Message);
                            //}
                            //finally
                            //{
                            //	context.Response.End();
                            //}
                            break;

                        case "va":                                 // video attachment
                            VIDEO_ATTACHMENT va = SQMDocumentMgr.GetVideoAttachment(doc_id);
                            fileType = Path.GetExtension(va.FILE_NAME);

                            if (!string.IsNullOrEmpty(context.Request.QueryString["FILE_NAME"]))
                            {
                                fileName = context.Request.QueryString["FILE_NAME"];
                            }
                            else
                            {
                                fileName += fileType;
                            }

                            mimeType = SQM.Website.Classes.FileExtensionConverter.ToMIMEType(fileType);
                            context.Response.ContentType = mimeType;
                            //context.Response.BinaryWrite(a.ATTACHMENT_FILE.ATTACHMENT_DATA);

                            // mt  - use below for video streams ?
                            context.Response.AddHeader("content-disposition", "inline; filename=" + fileName);
                            context.Response.AddHeader("content-length", va.VIDEO_ATTACHMENT_FILE.VIDEO_ATTACH_DATA.Length.ToString());
                            context.Response.OutputStream.Write(va.VIDEO_ATTACHMENT_FILE.VIDEO_ATTACH_DATA, 0, va.VIDEO_ATTACHMENT_FILE.VIDEO_ATTACH_DATA.Length);
                            context.Response.Flush();
                            break;

                        default:                                 // document
                            DOCUMENT d = SQMDocumentMgr.GetDocument(doc_id);
                            fileType = Path.GetExtension(d.FILE_NAME);
                            // set this to whatever your format is of the image
                            context.Response.ContentType = fileType;
                            mimeType = SQM.Website.Classes.FileExtensionConverter.ToMIMEType(fileType);
                            context.Response.ContentType = mimeType;
                            //context.Response.AddHeader("content-length", d.DOCUMENT_DATA.Length.ToString());
                            //context.Response.OutputStream.Write(d.DOCUMENT_DATA, 0, d.DOCUMENT_DATA.Length);
                            context.Response.AddHeader("content-length", d.DOCUMENT_FILE.DOCUMENT_DATA.Length.ToString());
                            context.Response.OutputStream.Write(d.DOCUMENT_FILE.DOCUMENT_DATA, 0, d.DOCUMENT_FILE.DOCUMENT_DATA.Length);
                            context.Response.Flush();
                            break;
                        }
                    }
                }

                else
                {
                    context.Response.ContentType = "text/html";
                    context.Response.Write("<p>Document not found</p>");
                }
            }
            catch (Exception e)
            {
                //SQMLogger.LogException(e);
            }
        }