Logo 
Search:

MOSS Forum

Ask Question   UnAnswered
Home » Forum » MOSS       RSS Feeds

How MOSS Stores Office Documents

  Asked By: Abhilasha    Date: Jul 11    Category: MOSS    Views: 808

Using Search Web Service and additional coding, i have copied the path and binary content of a MS Word file into an external database. How do i use this binary content and open the document in MS Word ?



The functionality I need is to convert the documents living in MOSS store into TXT conent. I can use SP object model and OfficeInterop. Is there a way in SP object model to open docs and convert into txt?

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Mayur Mandal     Answered On: Jul 11

I have a business requirement to convert  the content  of a word  file into TXT. I did got it working. Here is the code just in case some one want to use:

[source: Internet]



1st Step

------------


IDataReader sqldr = null;

byte[] localfile;

int arraySize;

DbCommand dbcommand = searchdatabase.GetStoredProcCommand("spGetDocumentData");

sqldr = searchdatabase.ExecuteReader(dbcommand);

while (sqldr.Read())

{

localfile = (byte[]) sqldr["docBinary"];

arraySize = localfile.GetUpperBound(0);

FileStream fs1 = new FileStream("c:\\test.docx", FileMode.CreateNew);

fs1.Write(localfile, 0, arraySize+1);

fs1.Close();

}


2nd Step

--------------

Microsoft.Office.Interop.Word.Application newApp = new Microsoft.Office.Interop.Word.Application();

// specifying the Source & Target file  names

object Source = "c:\\test.docx";

object Target = "c:\\test.txt";

// Use for the parameter whose type are not known or

// say Missing

object Unknown = Type.Missing;

// Source document open  here

// Additional Parameters are not known so that are

// set as a missing type

newApp.Documents.Open(ref Source, ref Unknown,

ref Unknown, ref Unknown, ref Unknown,

ref Unknown, ref Unknown, ref Unknown,

ref Unknown, ref Unknown, ref Unknown,

ref Unknown, ref Unknown, ref Unknown, ref Unknown,ref Unknown);

// Specifying the format in which you want the output file

object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatText;

//Changing the format of the document

newApp.ActiveDocument.SaveAs(ref Target, ref format,

ref Unknown, ref Unknown, ref Unknown,

ref Unknown, ref Unknown, ref Unknown,

ref Unknown, ref Unknown, ref Unknown,

ref Unknown, ref Unknown, ref Unknown,

ref Unknown, ref Unknown);

// for closing the application

newApp.Quit(ref Unknown, ref Unknown, ref Unknown);

 
Didn't find what you were looking for? Find more on How MOSS Stores Office Documents Or get search suggestion and latest updates.




Tagged: