Can I extract a file from a foxpro general field?

旧巷老猫 提交于 2019-12-06 02:30:20

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!