tags:

views:

761

answers:

2

I'm porting a VFP 9 application to SQL Server. The VFP app has some tables with "general" fields in them. I get a byte array when query the field, and when I save it to disk, I can look inside and see it's a word document, or a Paint BMP, etc.

From reading around, I've found that the general field is a proprietary format and contains a thumbnail image of the preview of the document (amongst other things, I'm sure).

Can somebody point me to some code that would extract firstly the type of file, and then the actual file data that I can save as the original file. (Getting the preview image out would be nice too.)

Apparently back in the day, somebody wrote a program in foxpro called GENTOFIL.PRG which sounds like it converts general fields to a file. But, google doesn't help much when trying to find that!

+2  A: 

The "General" field type in VFP is a bit of an oddity...

From the VFP Help docs:

The General field contains a ten-byte reference to the actual contents of the field: a spreadsheet, a word processor document, or a picture, created by another application. The actual type and amount of data, however, depends on the Automation server that creates the object and whether you link or embed the OLE object.

If you link an OLE object, your table contains only the reference to the data and to the application that created it. If you embed an OLE object, the table contains a copy of the data as well as a reference to the application that created it. The size of a General field is limited only by the amount of available disk space.

The key thing to note here is that the "general" field type of VFP deals with Microsoft OLE objects and they can be either linked or embedded. Also, VFP's ability to directly manipulate OLE objects appears to be minimal because when invoking actions on contained OLE objects, the associated application is actually run to open/edit the contents of the OLE-bound "general" field.

If, as you have said, you are able to extract the file by hand, that's probably the best way to go about getting the files out, as even VFP provides minimal ways to interact with the data contained in general type fields.

Kit Roed
+3  A: 

If you know the content of the General field is a Word Document I have some Visual FoxPro code recommended by someone that should extract it.

* First create a form programmatically
loForm = CREATEOBJECT("Form") 

* Open your VFP table with the general field. Change name as needed
USE CustomerDocs.DBF IN 0 ALIAS WordData

loForm.AddObject("oleWordDoc", "oleBoundControl") 
loForm.oleWordDoc.AutoSize = .T. 

* bind general field to oleboundcontrol 
loForm.oleWordDoc.ControlSource = "WordData.gen1" 

lnCounter = 1

SCAN 
   * File names all the same with counter at end
   * You might have file name in another column in the table.
   lcFileName = "docfromgeneralfield" + TRANSFORM(lnCounter)
   lcFileName = FORCEEXT(lcFileName, "doc")

   * save data from general field to .doc file 
   loForm.oleWordDoc.SaveAs("lcFileName") 

   lnCounter = lnCounter + 1 
ENDSCAN 

RELEASE loForm

USE IN (SELECT("WordData"))

RETURN

If you need help extracting an image out of the table you can check out a Microsoft KB article I have used in the past.

http://support.microsoft.com/kb/894819

Rick Schummer Visual FoxPro MVP

Rick Schummer