How to open a word document from C# application
-
Hello, I am using C# desktop applications.Here I am saving some files into the database and i wanted to read those files back and depending upon my extension it should open in corresponding files.For eg,.doc file in msword,pdf in adobe like that. I am facing a problem in opening the file .I have binary data in a byte array.How will i do it.Please help seeism
-
Hello, I am using C# desktop applications.Here I am saving some files into the database and i wanted to read those files back and depending upon my extension it should open in corresponding files.For eg,.doc file in msword,pdf in adobe like that. I am facing a problem in opening the file .I have binary data in a byte array.How will i do it.Please help seeism
Most apps need physical files for their documents, so create a document file (could be in a temp folder), then pass its path to
Process.Start()
to launch the associated application to open it. Note: the app may remain open after you're done. :)Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
Hello, I am using C# desktop applications.Here I am saving some files into the database and i wanted to read those files back and depending upon my extension it should open in corresponding files.For eg,.doc file in msword,pdf in adobe like that. I am facing a problem in opening the file .I have binary data in a byte array.How will i do it.Please help seeism
What kind of error or problem are you getting? Can you provide more information on it? I have found very good link to store any kind of document in database using C#, that might help you. http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=112[^] HTH
Jinal Desai - LIVE Experience is mother of sage....
-
Most apps need physical files for their documents, so create a document file (could be in a temp folder), then pass its path to
Process.Start()
to launch the associated application to open it. Note: the app may remain open after you're done. :)Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
What kind of error or problem are you getting? Can you provide more information on it? I have found very good link to store any kind of document in database using C#, that might help you. http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=112[^] HTH
Jinal Desai - LIVE Experience is mother of sage....
Hi, I am not getting any error.I just want to open a file in the same application and now my problem is solved using this String new_FileName = Path.ChangeExtension(Path.GetTempFileName(), "txt"); File.WriteAllBytes(new_FileName, result); System.Diagnostics.Process.Start(new_FileName); But now i getting junk values for doc data.:(
-
Hi, I am not getting any error.I just want to open a file in the same application and now my problem is solved using this String new_FileName = Path.ChangeExtension(Path.GetTempFileName(), "txt"); File.WriteAllBytes(new_FileName, result); System.Diagnostics.Process.Start(new_FileName); But now i getting junk values for doc data.:(
why would you change the extension? if it is a Word document, NotePad will not be able to open it properly. The normal thing to do is to use two database fields: one for the filename (including extension!), one for the binary data (the actual file content). :confused:
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
Most apps need physical files for their documents, so create a document file (could be in a temp folder), then pass its path to
Process.Start()
to launch the associated application to open it. Note: the app may remain open after you're done. :)Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
why would you change the extension? if it is a Word document, NotePad will not be able to open it properly. The normal thing to do is to use two database fields: one for the filename (including extension!), one for the binary data (the actual file content). :confused:
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
Soory i pasted the code for txt here.I put it as doc while opening the doc file.For doc file it is coming junk data.For txt first char is printing SqlDataReader dr = cmd.ExecuteReader(); DataTable dt = new DataTable()); dt.Load(dr); result = (Byte[])dt.Rows[0]["File_Doc"]; when i check this result array it is contiaing the first byte value and all others r zero Why so
-
Soory i pasted the code for txt here.I put it as doc while opening the doc file.For doc file it is coming junk data.For txt first char is printing SqlDataReader dr = cmd.ExecuteReader(); DataTable dt = new DataTable()); dt.Load(dr); result = (Byte[])dt.Rows[0]["File_Doc"]; when i check this result array it is contiaing the first byte value and all others r zero Why so
use your database management tool to check the content of the field, and determine whether the problem is in storing or in retrieving the data. BTW: you don't need a DataReader, a simple ExecuteScalar could suffice, see here e.g.: Save An Image Into SQL Server 2000 Database[^] :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
use your database management tool to check the content of the field, and determine whether the problem is in storing or in retrieving the data. BTW: you don't need a DataReader, a simple ExecuteScalar could suffice, see here e.g.: Save An Image Into SQL Server 2000 Database[^] :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
use your database management tool to check the content of the field, and determine whether the problem is in storing or in retrieving the data. BTW: you don't need a DataReader, a simple ExecuteScalar could suffice, see here e.g.: Save An Image Into SQL Server 2000 Database[^] :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.