void GenerateAllFiles() { string offerID = string.Empty; if (GXGridView1.SelectedValue != null) { offerID = GXGridView1.SelectedDataKey.Value.ToString(); } else { offerID = GXGridView1SelectedValue.ToString(); } List <Attachment> listAttachments = Attachment.Table.Where(a => a.DocumentTypeID == Broker.DataAccess.DocumentType.GetByCode(Broker.DataAccess.DocumentType.PONUDA).ID&& a.DocumentID == int.Parse(offerID)).ToList(); if (listAttachments.Count > 0) { FileInfo[] fileInfo = new FileInfo[listAttachments.Count]; int i = 0; foreach (Attachment at in listAttachments) { fileInfo[i] = new FileInfo(at.RelativePath); i++; } dataGridFiles.DataSource = fileInfo; } else { Label1.Text = "Нема прикачено документи."; } dataGridFiles.DataBind(); }
protected void btnFile_Click(object sender, EventArgs e) { LinkButton button = (LinkButton)sender; string offerID = string.Empty; if (GXGridView1.SelectedValue != null) { offerID = GXGridView1.SelectedDataKey.Value.ToString(); } else { offerID = GXGridView1SelectedValue.ToString(); } string destinationPath = OfferAttachmens_Directory + @"\" + offerID; string file_path = destinationPath + @"\" + button.Text; FileInfo fi = new FileInfo(file_path); FileStream fs = fi.OpenRead(); byte[] byte_get = new byte[fs.Length]; fs.Read(byte_get, 0, byte_get.Length); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ClearContent(); HttpContext.Current.Response.ClearHeaders(); HttpContext.Current.Response.ContentType = AttachmentController.getMimeType(file_path); HttpContext.Current.Response.Charset = string.Empty; HttpContext.Current.Response.Cache.SetCacheability(System.Web.HttpCacheability.Public); HttpContext.Current.Response.AddHeader("Content-Disposition:", "attachment; filename=" + button.Text); HttpContext.Current.Response.OutputStream.Write(byte_get, 0, byte_get.Length); HttpContext.Current.Response.OutputStream.Flush(); HttpContext.Current.Response.OutputStream.Close(); HttpContext.Current.Response.End(); }
protected void btnAddAttachment_Click(object sender, EventArgs e) { string s = FileUpload1.AccessKey; if (FileUpload1.HasFile) { try { string IncomingFactureID = string.Empty; if (GXGridView1.SelectedValue != null) { IncomingFactureID = GXGridView1.SelectedDataKey.Value.ToString(); } else { IncomingFactureID = GXGridView1SelectedValue.ToString(); } string destinationPath = IncomingFactureAttachmens_Directory + @"\" + IncomingFactureID; if (!Directory.Exists(destinationPath)) { Directory.CreateDirectory(destinationPath); } string path = destinationPath + @"\" + FileUpload1.FileName; FileUpload1.SaveAs(path); Label1.Text = "Датотека: " + FileUpload1.PostedFile.FileName + "<br>" + FileUpload1.PostedFile.ContentLength + " B<br>" + "Тип на датотека: " + FileUpload1.PostedFile.ContentType; //int len = FileUpload1.PostedFile.ContentLength; Attachment a = new Attachment(); a.DocumentTypeID = Broker.DataAccess.DocumentType.GetByCode(Broker.DataAccess.DocumentType.NALOG).ID; a.DocumentID = Convert.ToInt32(IncomingFactureID); a.RelativePath = path; a.Insert(); } catch (Exception ex) { Label1.Text = ex.Message; } } else { Label1.Text = "Немате избрано валидна датотека."; } GenerateAllFiles(); }