c# - how to open file after read image bytes from the database -


i have used below code showing image in image picture box, add code opening file (pdf,image,...) after reading database

            int imageid = convert.toint32(imageidcombobox.text);              // read image bytes database , display in picture box             byte[] imagebytearray = productdb.readimage(imageid);             memorystream ms = new memorystream(imagebytearray);              imagepicturebox.image = system.drawing.image.fromstream(ms);             ms.close(); 

i have tried used below code not recognize response.

   ms.writeto(response.outputstream) 

you need save file somewhere. suggest use gettemppath method obtain temp file name.

after have saved file can open default program of machine using process class

some pseudo code:

string filename = "c:\temp\foo.pdf"; //or use path.gettemppath() ms.write(new streamwriter(filename)); //you may want use using statement file stream ensure file closed process.start(filename); 

https://msdn.microsoft.com/en-us/library/system.io.path.gettemppath(v=vs.110).aspx https://www.dotnetperls.com/process

edit

it seems pseudo code not work correctly ;-) here's snippet:

    byte[] imagebytearray = productdb.readimage(imageid);     string filename = path.gettemppath();      file.writeallbytes(filename, imagebytearray);      process.start(filename); 

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -