none
help me to store som page of a word document in db RRS feed

  • Question

  • hi

    (first of all sorry for my very bad English writing!)

    i need to store just first ten page of a word document in database ,

    my friend tell me i should 1)convert doc to xml 2)save this xml file as ntext to db

    and when i want to show this file  to user i can show it as html in user browser.

    for this idea i have a lot of problem .and now i still  can not convert word to xml in C# code.

    do you know other simpler way to this problem?(without convert to xml)?

    or if not ,help me to convert doc to xml  in c#

    tanks  a lot of all you!

    • Moved by Mio_Miao Tuesday, January 25, 2011 6:46 AM (From:Visual C# Language)
    Saturday, January 22, 2011 7:20 PM

All replies

  • For MS Office related questions use the Microsoft Office for Developers Forums .


    Mark the best replies as answers. "Fooling computers since 1971."

    http://rudedog2.spaces.live.com/default.aspx

    Sunday, January 23, 2011 5:19 PM
  • Hi neilabak,

    Welcome to the MSDN Forum.

    I’ll help you moving your thread into Word for Developers forum. You will get better and quicker response since more experts who are dedicated to this topic.

    Thank you for your understanding and support.

    Best Regards,

    Mio


    Mio Miao[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, January 25, 2011 6:45 AM
  • Hi,

    i think u need not convert the doc file to xml. Directly u can place the doc file in DB. To achieve this use the following code

    DB Side
    ---------------
    FileName     nvarchar(50)
    FileBytes     Image
    
    C#
    ----------------
    private byte[] GetFileBytes(string path)
    {
     if(System.IO.File.Exits(path))
      return System.IO.File.ReadAllBytes(path);
     else
      return null;
    }
    
    private void WriteAllBytes(byte[] fileBytes)
    {
      if(fileBytes != null)
      {
       System.IO.File.WriteAllBytes(@"C:\\Test\TestFile2.doc", fileBytes);
      }
    }
    
    private void InsertFileToDB()
    {
     byte[] fileBytes = GetFileBytes(@"C:\\Test\TestFile.doc");
     if(fileBytes != null)
     {
      SqlConnection con = new SqlConnection("Data Source=(local); Initial Catalog = TestDB;user id=sa;password=****");
      con.Open();
      
      SqlCommand cmd = new SqlCommand("INSERT INTO TESTTABLE (FileName, FileBytes) VALUES (@fileName,@fileBytes)");
      cmd.Parameters.AddWithValue("@fileName", "TestFile.txt");
      cmd.Parameters.AddWithValue("@fileBytes", fileBytes);
      
      cmd.Connection = con;
      cmd.ExecuteNonQuery();
      con.Close();
      MessageBox.Show("Inserted");
     }
    }
    
    private byte[] GetFileFromDB(string fileName)
    {
      SqlConnection con = new SqlConnection("Data Source=(local); Initial Catalog = TestDB;user id=sa;password=****");
      con.Open();
      
      SqlCommand cmd = new SqlCommand("SELECT FileBytes FROM TESTTABLE WHERE FileName =@fileName");
      cmd.Parameters.AddWithValue("@fileName", "TestFile.txt");
      
      cmd.Connection = con;
      object result =  cmd.ExecuteScalar();
      con.Close();
      return result;
    }
    
    
    private void WriteFile()
    {
      byte[] fileBytes = GetFileFromDB("TestFile.doc")
      WriteAllBytes(fileBytes);
      MessageBox.Show("File written successfully");
    }
    
    

    hope this will help u....

     


    Nagarjuna Dilip
    Tuesday, January 25, 2011 7:03 AM
  • Hi Neilabak

    If Nagarjuna's suggestion doesn't help, please tell us which version of Word you're working with. Also tell us more about what should happen with these documents, once they're in the database.


    Cindy Meister, VSTO/Word MVP
    Tuesday, January 25, 2011 7:46 AM
    Moderator
  • hi,

    is it solved ?


    Nagarjuna Dilip
    Wednesday, February 16, 2011 6:46 AM