Marvin kakuru

Marvin kakuru

  • 1.4k
  • 359
  • 160.8k

viewing and editing ms word doc saved as ole object in acces

Feb 19 2013 1:32 AM
hi i am trying to veiw as well edit my ms word document that i saved as an ole object below is the code i am currently using to download a copy of the document, but i need to edit the document directly i hope it is possible.

System.Data.OleDb.OleDbConnection conn = null;

System.Data.OleDb.OleDbCommand cmd = null;

System.Data.OleDb.OleDbDataReader reader = null;

System.IO.FileStream fileStream = null;

System.IO.BinaryWriter writer = null;

int bufferSize = 1000;

byte[] buffer = new byte[bufferSize];

long startIndex = 0;

long numberOfBytes = 0;

 

conn = new System.Data.OleDb.OleDbConnection("Provider" +

       "=Microsoft.Jet.OLEDB.4.0;Data Source=" + AccessFile.Text);

cmd = new System.Data.OleDb.OleDbCommand("SELECT [File] " +

      "FROM [File] WHERE [FileName] = '" +

      FileListView.SelectedItems[0].Text + "'", conn);

conn.Open();

 

reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess);

reader.Read();

fileStream = new System.IO.FileStream(DataFile.Text,

             System.IO.FileMode.OpenOrCreate,

             System.IO.FileAccess.Write);

writer = new System.IO.BinaryWriter(fileStream);

 

do {

    numberOfBytes = reader.GetBytes(0,

                    startIndex, buffer, 0, bufferSize);

    if(numberOfBytes == 0) {

        break;

    }

    writer.Write(buffer, 0, (int) numberOfBytes);

    startIndex += numberOfBytes;

} while (true);

writer.Flush();

 

thanks and best regards.