Inheritance: OptimizedPersistable
Example #1
0
 protected void UploadButton_Click(object sender, EventArgs e)
 {
   FileUpload file = (FileUpload)IssueDetailsView.FindControl("AttachmentFileUpload");
   if (file.HasFile)
   {
     HttpPostedFile postedFile = file.PostedFile;
     TextBox fileInfoTextBox = (TextBox)IssueDetailsView.FindControl("UploadTextBox");
     ListBox listBox = (ListBox)IssueDetailsView.FindControl("UploadsListBox");
     Attachment attachment = new Attachment(postedFile.FileName, file.FileName, fileInfoTextBox.Text, file.FileBytes, postedFile.ContentType, null);
     listBox.Items.Add(new ListItem(attachment.ToString(), attachment.FileName));
     SortedSetAny<Attachment> attachments;
     object updatedAttachments = Session["UpdatedAttachments"];
     if (updatedAttachments == null)
     {
       attachments = new SortedSetAny<Attachment>();
       Session["UpdatedAttachments"] = attachments;
     }
     else
       attachments = (SortedSetAny<Attachment>)updatedAttachments;
     attachments.Add(attachment);
     updateImage(0, attachment.FileName);
   }
 }
Example #2
0
 protected void OpenAttachmentLinkButton_Click(object sender, EventArgs e)
 {
   ListBox listBox = (ListBox)IssueDetailsView.FindControl("UploadsListBox");
   if (listBox.SelectedValue != null && listBox.SelectedValue.Length > 1)
   {
     UInt64 id = 0;
     UInt64.TryParse(listBox.SelectedValue, out id);
     if (id == 0)
     {
       object updatedAttachments = Session["UpdatedAttachments"];
       SortedSetAny<Attachment> attachments = (SortedSetAny<Attachment>)updatedAttachments;
       Attachment attachment = new Attachment(null, listBox.SelectedItem.Value, null, null, null, null);
       if (attachments.TryGetValue(attachment, ref attachment))
       {
         Response.AddHeader("content-disposition", "attachment;filename=" + attachment.FileName);
         Response.Cache.SetCacheability(HttpCacheability.NoCache);
         Response.ContentType = attachment.ContentType;
         Response.BinaryWrite(attachment.FileContent);
       }
     }
     else
     {
       try
       {
         int sessionId = -1;
         SessionBase session = null;
         try
         {
           session = s_sessionPool.GetSession(out sessionId);
           session.BeginUpdate();
           Attachment attachment = (Attachment)session.Open(id);
           session.Commit();
           Response.AddHeader("content-disposition", "attachment;filename=" + attachment.FileName);
           Response.Cache.SetCacheability(HttpCacheability.NoCache);
           Response.ContentType = attachment.ContentType;
           Response.BinaryWrite(attachment.FileContent);
           s_sharedReadOnlySession.ForceDatabaseCacheValidation();
         }
         catch (Exception ex)
         {
           session?.Abort();
           Console.Out.WriteLine(ex.StackTrace);
         }
         finally
         {
           s_sessionPool.FreeSession(sessionId, session);
         }
       }
       catch (System.Exception ex)
       {
         Console.WriteLine(ex.ToString());
       }
     }
     listBox.Items.RemoveAt(listBox.SelectedIndex);
   }
 }
Example #3
0
 protected void OpenAttachmentLinkButton_Click(object sender, EventArgs e)
 {
   ListBox listBox = (ListBox)IssueDetailsView.FindControl("UploadsListBox");
   if (listBox.SelectedValue != null && listBox.SelectedValue.Length > 1)
   {
     UInt64 id = 0;
     UInt64.TryParse(listBox.SelectedValue, out id);
     if (id == 0)
     {
       object updatedAttachments = Session["UpdatedAttachments"];
       SortedSetAny<Attachment> attachments = (SortedSetAny<Attachment>)updatedAttachments;
       Attachment attachment = new Attachment(null, listBox.SelectedItem.Value, null, null, null, null);
       if (attachments.TryGetValue(attachment, ref attachment))
       {
         Response.AddHeader("content-disposition", "attachment;filename=" + attachment.FileName);
         Response.Cache.SetCacheability(HttpCacheability.NoCache);
         Response.ContentType = attachment.ContentType;
         Response.BinaryWrite(attachment.FileContent);
       }
     }
     else
     {
       try
       {
         string dataPath = HttpContext.Current.Server.MapPath("~/IssuesDatabase");
         using (SessionNoServer session = new SessionNoServer(dataPath, 2000, true, true))
         {
           session.BeginUpdate();
           Attachment attachment = (Attachment)session.Open(id);
           session.Commit();
           Response.AddHeader("content-disposition", "attachment;filename=" + attachment.FileName);
           Response.Cache.SetCacheability(HttpCacheability.NoCache);
           Response.ContentType = attachment.ContentType;
           Response.BinaryWrite(attachment.FileContent);
         }
       }
       catch (System.Exception ex)
       {
         Console.WriteLine(ex.ToString());
       }
     }
     listBox.Items.RemoveAt(listBox.SelectedIndex);
   }
 }