private void uploadButton_Click(object sender, EventArgs e) { try { byte[] file; using (FileStream stream = new FileStream(uploadedFile, FileMode.Open, FileAccess.Read)) { using (BinaryReader reader = new BinaryReader(stream)) { file = reader.ReadBytes((int)stream.Length); } } DocAuth.Model.Document doc = new Model.Document { Content = file, createdDate = DateTime.Now, FileName = fileName, Id = _documentLastGuid }; using (DocsDBContext db = new DocsDBContext()) { db.Documents.Add(doc); db.SaveChanges(); } MessageBox.Show("Document uploaded successfully"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public DocAuth.Model.Document getFileById(Guid id) { DocAuth.Model.Document doc = null; using (DocsDBContext db = new DocsDBContext()) { doc = db.Documents.FirstOrDefault(x => x.Id == id); } return(doc); }