c# - Store MS Word .doc in database and then get it out again -


I have this to store the word dock in SQL:

  byte [ ] Bytes = New Byte [Uploader. Uploaded file [0] Input stream. Length]; Var storedFile = new email_attachment (); String strFullPath = uploader. Uploaded file [0] .FileName; String strFileName = path GetFileName (strFullPath); StoredFile.email_attachment_id = Guide. Newguide (); StoredFile.emailer_id = New Guide (dropMailers.SelectedValue); StoredFile.file_name = strFileName; StoredFile.file_data = bytes; Db.email_attachments.InsertOnSubmit (storedFile); Db.SubmitChanges ();  

To get this back I use:

  storedFile = db.email_attachments.Where (a => a.email_attachment_id.ToString () = = Drop attachments, selected valleys). Single (); String strpath = System.Web.Hosting.HostingEnvironment.MapPath ("~ / storage / email / attachment"); File. WhiteElebites (Path.Combine (Streets, stored file.file_name), stored file.file_data. ToArray ()); System.IO.FileInfo file = new system.IO.FileInfo (Path.Combine (strPath, storedFile.file_name)); If (File! = Null & File. Axis) {Response.Clear (); Response.AddHeader ("content-dispute", "attachment; filename =" + file.Name); Response.AddHeader ("content-length", file. Length.tostring ()); Response.ContentType = "app / octet-stream"; Response.WriteFile (file.FullName); Response.End (); } Else {//Response.Write ((This file does not exist.);); } Problems: I'm getting the doctor back empty, and I believe in saving this also in the file system and then writing it in the feedback stream is not very efficient. I am thinking that the step can be left any help or information would be greatly appreciated.   

To start this code, see:

  byte [ ] Bytes = New Byte [Uploader. Uploaded file [0] Input stream. Length]; Var storedFile = new email_attachment (); String strFullPath = uploader. Uploaded file [0] .FileName; String strFileName = path GetFileName (strFullPath); StoredFile.email_attachment_id = Guide. Newguide (); StoredFile.emailer_id = New Guide (dropMailers.SelectedValue); StoredFile.file_name = strFileName; StoredFile.file_data = bytes; Db.email_attachments.InsertOnSubmit (storedFile); Db.SubmitChanges ();  

I can make you an empty array - but I can not see where you are making it anywhere. You should not read from InputStream instead of searching for your length?

(You can copy from the input stream MemoryStream , and then using toArray to get a bit of sample code to exit a byte array at the end Not a whole stream is copied around - and in .NET 4 even the WriteTo method makes it easy.)

I have not yet I have not seen the code - first let's make sure that you actually get some data in the database first ...


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -