public static byte[] GetAttachmentByteArray(decimal attachmentID) { ATTACHMENT doc = GetAttachment(attachmentID); byte[] bytes = doc.ATTACHMENT_FILE.ATTACHMENT_DATA; return(bytes); }
public static ATTACHMENT DeleteAttachment(decimal attachmentID) { ATTACHMENT this_at = null; try { using (PSsqmEntities entities = new PSsqmEntities()) { ATTACHMENT_FILE this_atfile = (from d in entities.ATTACHMENT_FILE where (d.ATTACHMENT_ID == attachmentID) select d).Single(); if (this_atfile != null) { entities.DeleteObject(this_atfile); entities.SaveChanges(); } this_at = (from d in entities.ATTACHMENT where (d.ATTACHMENT_ID == attachmentID) select d).Single(); if (this_at != null) { entities.DeleteObject(this_at); entities.SaveChanges(); } } } catch (Exception e) { //SQMLogger.LogException(e); } return(this_at); }
public static string GetAttachImageSourceString(ATTACHMENT doc) { string src = "data:image/"; //jpg;base64,"; switch (Path.GetExtension(doc.FILE_NAME)) { case ".bmp": src += "bmp"; break; case ".jpg": src += "jpg"; break; case ".jpeg": src += "jpeg"; break; case ".gif": src += "gif"; break; default: src += "png"; break; } src += ";base64," + Convert.ToBase64String(doc.ATTACHMENT_FILE.ATTACHMENT_DATA); return(src); }
public void rptAttachList_OnItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item) { string[] fileTypes = { ".mov", ".qt", ".wmv", ".yuv", ".m4v", ".3gp", ".3g2", ".nsv" }; try { ATTACHMENT attachment = (ATTACHMENT)e.Item.DataItem; if (fileTypes.Any(attachment.FILE_NAME.ToLower().Contains) == false) { Image img = (Image)e.Item.FindControl("imgBindAttachment"); string[] args = attachment.FILE_NAME.Split('.'); if (args.Length > 0) { string ext = args[args.Length - 1]; img.ImageUrl = "~/images/filetype/icon_" + ext.ToLower() + ".jpg"; img.CssClass = ""; } else { img.Visible = false; } pnlListVideo.Attributes.Remove("Class"); System.Web.UI.HtmlControls.HtmlGenericControl div = (System.Web.UI.HtmlControls.HtmlGenericControl)e.Item.FindControl("divAttachment"); div.Attributes.Remove("Class"); } } catch { } } }
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); } }
public ActionResult DeleteConfirmed(short id) { ATTACHMENT attachment = db.ATTACHMENTs.Find(id); db.ATTACHMENTs.Remove(attachment); db.SaveChanges(); return(RedirectToAction("Index")); }
// // GET: /Attachment/Details/5 public ActionResult Details(short id = 0) { ATTACHMENT attachment = db.ATTACHMENTs.Find(id); if (attachment == null) { return(HttpNotFound()); } return(View(attachment)); }
public ActionResult Edit(ATTACHMENT attachment) { if (ModelState.IsValid) { db.Entry(attachment).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.UPREQUESTID = new SelectList(db.UPREQUESTs, "ID", "CREATEDBY", attachment.UPREQUESTID); return(View(attachment)); }
// // GET: /Attachment/Edit/5 public ActionResult Edit(short id = 0) { ATTACHMENT attachment = db.ATTACHMENTs.Find(id); if (attachment == null) { return(HttpNotFound()); } ViewBag.UPREQUESTID = new SelectList(db.UPREQUESTs, "ID", "CREATEDBY", attachment.UPREQUESTID); return(View(attachment)); }
public ActionResult Create(ATTACHMENT attachment) { if (ModelState.IsValid) { db.ATTACHMENTs.Add(attachment); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.UPREQUESTID = new SelectList(db.UPREQUESTs, "ID", "CREATEDBY", attachment.UPREQUESTID); return(View(attachment)); }
//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); } }
public static string GetAttachImageSourceString(decimal attachmentID) { ATTACHMENT doc = GetAttachment(attachmentID); if (doc != null && doc.ATTACHMENT_FILE != null) { return(GetAttachImageSourceString(doc)); } else { return(""); } }
public ActionResult DeleteAttachment(short id) { ATTACHMENT attachment = db.ATTACHMENTs.Find(id); String filepath = attachment.CONTENT; if (System.IO.File.Exists(filepath)) { System.IO.File.Delete(filepath); } db.ATTACHMENTs.Remove(attachment); db.SaveChanges(); return(Redirect(ControllerContext.HttpContext.Request.UrlReferrer.ToString())); }
public static ATTACHMENT GetAttachment(decimal attachmentID) { ATTACHMENT ret = null; try { using (PSsqmEntities entities = new PSsqmEntities()) { ret = (from d in entities.ATTACHMENT.Include("ATTACHMENT_FILE") where ( (d.ATTACHMENT_ID == attachmentID) ) select d).Single(); } } catch (Exception e) { //SQMLogger.LogException(e); ret = null; } return(ret); }
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); } }
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(); } } }
public static ATTACHMENT AddAttachment(String filename, String description, decimal?display_type, string docScope, int recordType, decimal recordID, string recordStep, string sessionID, Stream file, int Incident_Section) { ATTACHMENT ret = null; try { using (PSsqmEntities entities = new PSsqmEntities()) { ATTACHMENT d = new ATTACHMENT(); d.FILE_NAME = filename; d.FILE_DESC = description; //To-do: what do we do when company_id is not set, like when they choose this // from the Business Org master screen? d.COMPANY_ID = SessionManager.EffLocation.Company.COMPANY_ID; d.OWNER_ID = SessionManager.UserContext.Person.PERSON_ID; d.UPLOADED_BY = SessionManager.UserContext.Person.FIRST_NAME + " " + SessionManager.UserContext.Person.LAST_NAME; d.UPLOADED_DT = WebSiteCommon.CurrentUTCTime(); d.LANGUAGE_ID = (int)SessionManager.UserContext.Person.PREFERRED_LANG_ID; d.ATTACHMENT_SCOPE = docScope; d.RECORD_TYPE = recordType; d.RECORD_ID = recordID; // we might not have the record id when the attaachment is created d.RECORD_STEP = recordStep; d.SESSION_ID = sessionID; d.INCIDENT_SECTION = Incident_Section; if (display_type.HasValue) { d.DISPLAY_TYPE = display_type.Value; } if (d.ATTACHMENT_FILE == null) { d.ATTACHMENT_FILE = new ATTACHMENT_FILE(); } //read in the file contents file.Seek(0, SeekOrigin.Begin); byte[] bytearray = new byte[file.Length]; int count = 0; while (count < file.Length) { bytearray[count++] = Convert.ToByte(file.ReadByte()); } d.ATTACHMENT_FILE.ATTACHMENT_DATA = bytearray; d.FILE_SIZE = file.Length; // d.DISPLAY_TYPE = Path.GetExtension(filename); entities.AddToATTACHMENT(d); entities.SaveChanges(); ret = d; } } catch (Exception e) { //SQMLogger.LogException(e); ret = null; } return(ret); }
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); } }