Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. How to open a word document from C# application

How to open a word document from C# application

Scheduled Pinned Locked Moved C#
helpcsharpdatabaseadobedata-structures
11 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S 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

    L Offline
    L Offline
    Luc Pattyn
    wrote on last edited by
    #2

    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.

    S 2 Replies Last reply
    0
    • S 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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #3

      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....

      S 1 Reply Last reply
      0
      • L Luc Pattyn

        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.

        S Offline
        S Offline
        seeism
        wrote on last edited by
        #4

        hey thanks for that this is what i actually want.Now i able to open a word document if my file that stored was doc but it is coming as junk value.What could be the reason ??? seeism

        1 Reply Last reply
        0
        • L Lost User

          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....

          S Offline
          S Offline
          seeism
          wrote on last edited by
          #5

          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.:(

          L 1 Reply Last reply
          0
          • S seeism

            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.:(

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #6

            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.

            S 1 Reply Last reply
            0
            • L Luc Pattyn

              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.

              S Offline
              S Offline
              seeism
              wrote on last edited by
              #7

              Hi, I am able to read only the first char of bytes from db.What could be the reason.Now in txt file ,it is opening and prints the first char but for doc,it is coming junk data seeism

              1 Reply Last reply
              0
              • L Luc Pattyn

                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.

                S Offline
                S Offline
                seeism
                wrote on last edited by
                #8

                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

                L 1 Reply Last reply
                0
                • S seeism

                  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

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #9

                  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.

                  S 2 Replies Last reply
                  0
                  • L Luc Pattyn

                    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.

                    S Offline
                    S Offline
                    seeism
                    wrote on last edited by
                    #10

                    I am not much familiar with sql server.How to view the binary data in sql server. ??

                    1 Reply Last reply
                    0
                    • L Luc Pattyn

                      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.

                      S Offline
                      S Offline
                      seeism
                      wrote on last edited by
                      #11

                      Hey my probs was solved.oops that was a mistake in the stored proc where i didn mentioned the size of binary data.SO only one data was storing:) thanks a lot for ur help.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups