Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# DBF文件名被截断_C#_Oledb_Dbf - Fatal编程技术网

C# DBF文件名被截断

C# DBF文件名被截断,c#,oledb,dbf,C#,Oledb,Dbf,我使用下面的代码创建了一个dbf文件并填充了它,一切正常。问题是文件名被截断为最多8个字符。你知道为什么或者如何使文件名保持完整吗 string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+path+";Extended Properties=dBase IV"; OleDbConnection connection = new OleDbConnection(connectionString);

我使用下面的代码创建了一个dbf文件并填充了它,一切正常。问题是文件名被截断为最多8个字符。你知道为什么或者如何使文件名保持完整吗

string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+path+";Extended Properties=dBase IV";
OleDbConnection connection = new OleDbConnection(connectionString);
        connection.Open();
cmd.CommandText = @"CREATE TABLE calendfull(
                                date1 datetime ,
                                day1 int ,
                                month1 int ,
                                year1 int ,
                                dow int ,
                                endmonth int  
                                )";

            cmd.ExecuteNonQuery();

  foreach (DataRow row in calend.Rows)
            {
                day = Convert.ToInt32(row["day"]);
                year = Convert.ToInt32(row["year"]);
                month = Convert.ToInt32(row["month"]);
                dow = Convert.ToInt32(row["dow"]);
                endmonth = Convert.ToInt32(row["endmonth"]);
                date1 = Convert.ToDateTime(row["date1"]);

                cmd.CommandText = @"insert into calendFull  values ('" + date1 + "'," + day + "," + month + "," + year + "," + dow + "," + endmonth + ")";
                cmd.ExecuteNonQuery();
            }

DBF文件名遵循8.3命名规范,因此名称不能超过8个字符

但是等等,我看到一些dbf文件的名称大于8个字符。

是的,这是允许的,但当您在命令提示中查看时,它们的实际名称类似于文件名。e、 g
largef~1

那么我如何读取它们呢?您应该使用kernel32.dll获取它们的简称

代码如下:

    public string GetShortFileName(string fileDirectory, string fileNameWithExtension)
    {
        StringBuilder temp = new StringBuilder(255);

        string path = System.IO.Path.Combine(fileDirectory, fileNameWithExtension);

        int n = GetShortPathName(path, temp, 255);

        if (n == 0)
            throw new NotImplementedException();

        string extension = System.IO.Path.GetExtension(path);

        return ((temp.ToString().Split('\\')).Last()).ToLower();//.Replace(extension, string.Empty);
    }

    [System.Runtime.InteropServices.DllImport("kernel32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
            public static extern int GetShortPathName(
        [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr)]    
        string path,
        [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr)]    
        StringBuilder shortPath,
        int shortPathLength);

DBF文件名遵循8.3命名规范,因此名称不能超过8个字符

但是等等,我看到一些dbf文件的名称大于8个字符。

是的,这是允许的,但当您在命令提示中查看时,它们的实际名称类似于文件名。e、 g
largef~1

那么我如何读取它们呢?您应该使用kernel32.dll获取它们的简称

代码如下:

    public string GetShortFileName(string fileDirectory, string fileNameWithExtension)
    {
        StringBuilder temp = new StringBuilder(255);

        string path = System.IO.Path.Combine(fileDirectory, fileNameWithExtension);

        int n = GetShortPathName(path, temp, 255);

        if (n == 0)
            throw new NotImplementedException();

        string extension = System.IO.Path.GetExtension(path);

        return ((temp.ToString().Split('\\')).Last()).ToLower();//.Replace(extension, string.Empty);
    }

    [System.Runtime.InteropServices.DllImport("kernel32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
            public static extern int GetShortPathName(
        [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr)]    
        string path,
        [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr)]    
        StringBuilder shortPath,
        int shortPathLength);
更改oledb提供程序:

更改oledb提供程序:


创建文件的代码在哪里?我在这里遗漏了什么吗?我更新了问题以包含整个代码,创建和填充创建文件的代码在哪里?我在这里遗漏了什么吗?我更新了问题以包含整个代码,创建并填充使用
kernel32.dll
获取短名称?我与dBASE和FoxPro合作多年。文件名的长度可以超过8个字符,并且可以在Windows中以全名引用。这张图片中还有更多的东西——显然没有显示出来,因为OP提供的代码与文件或其名称无关。我也已经使用
dbf
文件多年了。我看到了这个问题。您可以搜索它(dbf文件名限制)并查看我是否为真。@MichaelPerrenoud查看此()。使用
Microsoft.Jet.Oledb
使用
kernel32.dll
获取短名称时似乎会发生这种情况?我与dBASE和FoxPro合作多年。文件名的长度可以超过8个字符,并且可以在Windows中以全名引用。这张图片中还有更多的东西——显然没有显示出来,因为OP提供的代码与文件或其名称无关。我也已经使用
dbf
文件多年了。我看到了这个问题。您可以搜索它(dbf文件名限制)并查看我是否为真。@MichaelPerrenoud查看此()。似乎在使用Microsoft.Jet.Oledb时会发生这种情况