How do I OPEN a stored excel file in SQL Server 2008 via C# -


i have stored excel file in sql server 2008 db (as varbinary(max)) following (so far, hard coded) way:

// c# - visual studio 2008 var update = new sqlcommand("update requests set attachment = @xls" +         " requestsid = 27", conn);      update.parameters.addwithvalue("xls", file.readallbytes("c:/afolder/hello.xlsx"));      update.executenonquery(); 

it works, i want open too!
how do that? note, not read blob-data, open actual "hello.xlsx" file.

i have tried following: http://dotnetsoldier.blogspot.com/2007/07/how-to-retrieve-blob-object-in-winforms.html can see works, "binary.length" size of "hello.xlsx" when executing - file doesn´t open, , that´s problem.

please me out!

edit: here code use "open" spreadsheet:

sqlconnection conn =         new sqlconnection            (global::my_project.properties.settings.default.db_1connectionstring);       conn.open();       sqlcommand cmd = new sqlcommand("select attachment requests requestsid = 27", conn);      cmd.commandtype = commandtype.text;       sqldatareader reader = cmd.executereader(commandbehavior.closeconnection);      //      string documentname = null;      filestream fstream = null;      binarywriter bwriter = null;      //      //      //      byte[] binary = null;      const int chunksize = 100;      int sizetowrite = 0;      memorystream mstream = null;      //      while (reader.read())      {         documentname = reader["attachment"].tostring();         // create file hold output.         fstream = new filestream(@"c:\" + documentname, filemode.openorcreate, fileaccess.write);         bwriter = new binarywriter(fstream);         binary = (reader["attachment"]) byte[];         sizetowrite = chunksize;         mstream = new memorystream(binary);         //         (int = 0; < binary.getupperbound(0) - 1; = + chunksize)         {            if (i + chunksize >= binary.length) sizetowrite = binary.length - i;            byte[] chunk = new byte[sizetowrite];            mstream.read(chunk, 0, sizetowrite);            bwriter.write(chunk);            bwriter.flush();         }         bwriter.close();         fstream.close();      }      fstream.dispose();       conn.close(); 

the code posted looks writes spreadsheet disc can't see code open it. need use

system.diagnostics.process.start(@"c:\" + documentname) 

i think.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -