0
Answer

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

Marvin kakuru

Marvin kakuru

11y
1.4k
1
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.