如何提取在 FoxPro 表中以 BLOB 形式存储的文件?

发布于 2024-12-18 01:34:29 字数 153 浏览 2 评论 0原文

我有一些 Foxpro 表,其中之一包含 Blob 字段。我知道存储在 Blob(MapPoint 文件)中的数据类型,但我不知道如何提取它,因为我没有 FoxPro(我无法轻松获取它)。

有没有办法获取 .DBF 和 .FPT 文件并提取其中存储的 MapPoint 文件?

I have some Foxpro tables, one of which includes a Blob field. I know the data type stored within the Blob (a MapPoint file), but I don't how to extract it, because I don't have FoxPro (not can I easily obtain it).

Is there a way to take the .DBF and .FPT files and extract the MapPoint files stored within?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

逆夏时光 2024-12-25 01:34:29

您可以使用 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 驱动程序。

You can use C# and ADO.NET to extract the data into files. Here is some sample code:

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();
        }
    }
}

Visit Microsoft OLE DB Provider for Visual FoxPro 9.0 if you need the FoxPro driver.

べ繥欢鉨o。 2024-12-25 01:34:29

上一个链接显示了如何连接
从 C# 到 VFP。该答案实际上显示了与 OleDbProvider 的连接,这与 DaveB 的答案类似,但是,VFP 不是 SQLServer 连接,而是使用 VFP OleDbProvider,可在 Microsoft 的 VFP 网站

相互配合使用(连接到 VFP OleDB)并运行查询。连接字符串只需指向数据所在的物理路径,并且可以从该文件夹中的任何.dbf 进行查询。您不必显式连接到实际的“数据库”,因为 VFP 暗示路径就是数据库的位置。

无论如何,与戴夫一起提出的另一个问题应该能够获取您的数据并将其写入流。唯一需要注意的是,您正在写入的文件流也请确保它是二进制文件。否则,每当您写入一个作为 {enter} 键的字节时,可能会强制使用尾随的 {line feed} 进行写入。我发现很久以前在构建二维条形码时编写二进制图像文件时遇到了困难,而且它变得一团糟。

This previous link shows how to connect
to VFP from C#. That answer actually shows connection with OleDbProvider which is similar to answer by DaveB, however, VFP is NOT SQLServer connection and uses VFP OleDbProvider which is available at Microsoft's website for VFP

Used in conjunction with each other (connecting to VFP OleDB) and running query. The connection string only needs to point to the physical path where the data resides, and can query from any .dbf in that folder. You do not have to explicitly connect to an actual "database" as VFP implies a path IS the location of the database.

Anyhow, the other question, joined with Dave should be able to get your data available and write it to a stream. The only other caveat is that the file stream that you are writing too, make sure its a binary file. Otherwise, anytime you write a byte that is an {enter} key, might be forced written with a trailing {line feed}. I found that one out the hard way a long time ago writing binary image files when building 2d bar codes and it getting messed up.

一桥轻雨一伞开 2024-12-25 01:34:29

我需要提取一些 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";

I needed to pull some PDF files that were being stored in what I believe is a memo field in FoxPro. The schema listed the field as LONGVARCHAR.

I was able to use the source code provided, but needed to change the SQL or I would get a casting error.

If I pulled the PDF file out as a string, it would get truncated whenever it ran into a NULL \0 value in the BLOB.

Here is the SQL I used:

string sqlSelect = "SELECT cast(inc_rawdata as Blob) as inc_rawdata, inc_filename  FROM F2_522_SYS_MAP_FILES";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文