2011-11-24 95 views
1

我有一些Foxpro表,其中一個包括一個Blob字段。我知道存儲在Blob(MapPoint文件)中的數據類型,但我沒有如何提取它,因爲我沒有FoxPro(我不能輕易獲得它)。如何提取在FoxPro表中存儲爲BLOB的文件?

有沒有辦法讓.DBF和.FPT文件並提取存儲在內的MapPoint文件?

回答

1

您可以使用C#和ADO.NET將數據提取到文件中。下面是一些示例代碼:

using System; 
using System.Data; 
using System.Data.OleDb; 
using System.IO; 

namespace SaveFoxProMemoFieldAsFile 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      string connectionString = @"Provider=VFPOLEDB.1;Data Source=C:\data\;Collating Sequence=MACHINE;Null=Yes"; 

      string sqlSelect = "SELECT filedata FROM filelist"; 
      int fileNumber = 1; 
      using (OleDbConnection connection = new OleDbConnection(connectionString)) 
      { 
       using(OleDbCommand command = connection.CreateCommand()) 
       { 
        command.CommandText = sqlSelect; 
        command.CommandType = CommandType.Text; 

        try 
        { 
         connection.Open(); 
         using(OleDbDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection)) 
         { 
          if(reader.HasRows) 
          { 
           while(reader.Read()) 
           { 
            byte[] binaryData = (byte[])reader["filedata"]; 

            FileStream fs = new FileStream(string.Format(@"C:\data\file_{0}.pdf", fileNumber++), FileMode.OpenOrCreate, FileAccess.Write); 
            fs.Write(binaryData, 0, binaryData.Length); 
            fs.Close(); 
           } 
          } 
         } 
        } 
        catch 
        { 
         throw; 
        } 
       } 
      } 

      Console.WriteLine("Program execution complete"); 
      Console.WriteLine("Press any key to end"); 
      Console.ReadKey(); 
     } 
    } 
} 

訪問Microsoft OLE DB Provider for Visual FoxPro 9.0如果您需要的FoxPro驅動程序。

0

上一個鏈接顯示如何連接 to VFP from C#。該答案實際上顯示與OleDbProvider的連接類似於DaveB的答案,但是,VFP不是SQLServer連接,並使用VFP OleDbProvider,它可在Microsoft's website for VFP

連接彼此(連接到VFP OleDB)和運行查詢。連接字符串只需要指向數據所在的物理路徑,並且可以從該文件夾中的任何.dbf進行查詢。您不必顯式連接到實際的「數據庫」,因爲VFP意味着路徑是數據庫的位置。

無論如何,與Dave結合的另一個問題應該是能夠獲取數據並將其寫入流中。唯一的另一個警告是你正在寫的文件流也確保它是一個二進制文件。否則,無論何時您寫入一個{enter}鍵的字節,都可能被強制寫入{換行符}。我發現很久以前,在構建二維條碼時編寫二進制圖像文件困難重重,而且越來越糟糕。

0

我需要拉一些PDF文件存儲在我相信是FoxPro中的備註字段。該模式將該字段列爲LONGVARCHAR

我能夠使用提供的源代碼,但需要更改SQL或我會得到一個轉換錯誤。

如果我將PDF文件以字符串的形式提取出來,只要它遇到BLOB中的NULL \0值就會被截斷。

這裏是我使用的SQL:

string sqlSelect = "SELECT cast(inc_rawdata as Blob) as inc_rawdata, inc_filename FROM F2_522_SYS_MAP_FILES"; 
相關問題