Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Problem when reading DBF files

Problem when reading DBF files

Scheduled Pinned Locked Moved C#
csshelp
9 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vuthaianh
    wrote on last edited by
    #1

    Hi all, I've got a small problem when i tried to read DBF files. I'm using OleDb provider. The problem is i just could read dbf files that have the length of filename which are less than or equal to 8 (not including extension). I can't understand this. Thanks a lot

    L E 2 Replies Last reply
    0
    • V vuthaianh

      Hi all, I've got a small problem when i tried to read DBF files. I'm using OleDb provider. The problem is i just could read dbf files that have the length of filename which are less than or equal to 8 (not including extension). I can't understand this. Thanks a lot

      L Offline
      L Offline
      lmoelleb
      wrote on last edited by
      #2

      DBF files are from the age of DOS, hence the 8.3 name limitation. Apparently no one cared to update it, and I doubt they will now as it really shouldn't be used anymore. There might be a decent solution, but my workaround was copying the file to a temp location to get the legal name.

      K 1 Reply Last reply
      0
      • L lmoelleb

        DBF files are from the age of DOS, hence the 8.3 name limitation. Apparently no one cared to update it, and I doubt they will now as it really shouldn't be used anymore. There might be a decent solution, but my workaround was copying the file to a temp location to get the legal name.

        K Offline
        K Offline
        Kiran Kumar Singani
        wrote on last edited by
        #3

        Hi, what is database connection string your using. Check the connection strain properly. Regards, Kiran Kumar Singani The Dream is not what you see in sleep........Dream is the thing which does not let you sleep

        V 1 Reply Last reply
        0
        • V vuthaianh

          Hi all, I've got a small problem when i tried to read DBF files. I'm using OleDb provider. The problem is i just could read dbf files that have the length of filename which are less than or equal to 8 (not including extension). I can't understand this. Thanks a lot

          E Offline
          E Offline
          Evan Stein
          wrote on last edited by
          #4

          Hi. By all means, you should continue to find out why the driver thinks it's a DOS program! But if the driver turns out to be inflexible, you can adapt the file name to the mangled "FILE~01.DBF" type of format. I've been trying to post the code to you all day, but there's something about the message that causes the Code Project to time out. I'm reduced to hinting! It's a function in Kernel32 called GetShortPathName(), and I found the C# example myself using Google when I was in a similar situation. If you have trouble finding it, we can figure out some other way of getting you the code. Hope this helps. Evan

          V 1 Reply Last reply
          0
          • K Kiran Kumar Singani

            Hi, what is database connection string your using. Check the connection strain properly. Regards, Kiran Kumar Singani The Dream is not what you see in sleep........Dream is the thing which does not let you sleep

            V Offline
            V Offline
            vuthaianh
            wrote on last edited by
            #5

            Hi Kiran Kumar Singani, Thanks for your answer The ConnectionString I'm using is "Provider=Microsoft.Jet.OLEDB.4.0; Data Source= " + directoryName + "; Extended Properties=dBASE IV; User ID=; Password=;" It just works fine with all dbf files that has the length of filename less than or equal to 8. Thanks again

            1 Reply Last reply
            0
            • E Evan Stein

              Hi. By all means, you should continue to find out why the driver thinks it's a DOS program! But if the driver turns out to be inflexible, you can adapt the file name to the mangled "FILE~01.DBF" type of format. I've been trying to post the code to you all day, but there's something about the message that causes the Code Project to time out. I'm reduced to hinting! It's a function in Kernel32 called GetShortPathName(), and I found the C# example myself using Google when I was in a similar situation. If you have trouble finding it, we can figure out some other way of getting you the code. Hope this helps. Evan

              V Offline
              V Offline
              vuthaianh
              wrote on last edited by
              #6

              Hi Evan, The ConnectionString i'm using to read *dbf files is "Provider=Microsoft.Jet.OLEDB.4.0; Data Source= " + directoryName + "; Extended Properties=dBASE IV; User ID=; Password=;"" My current solution is copying that DBF file to temporary DBF file which has a legal name (length of filename <= 8), processing on the temporary file and deleting it after finishing. If you have a better solution, Please let me know. Thanks a lot.

              E 2 Replies Last reply
              0
              • V vuthaianh

                Hi Evan, The ConnectionString i'm using to read *dbf files is "Provider=Microsoft.Jet.OLEDB.4.0; Data Source= " + directoryName + "; Extended Properties=dBASE IV; User ID=; Password=;"" My current solution is copying that DBF file to temporary DBF file which has a legal name (length of filename <= 8), processing on the temporary file and deleting it after finishing. If you have a better solution, Please let me know. Thanks a lot.

                E Offline
                E Offline
                Evan Stein
                wrote on last edited by
                #7

                [DllImport("Kernel32", CharSet = CharSet.Auto)]
                static extern Int32 GetShortPathName(
                String path, // input string
                StringBuilder shortPath, // output string
                Int32 shortPathLength); // StringBuilder.Capacity
                public static string ConvertLongPathToShort(string longPathName)
                {
                StringBuilder shortNameBuffer;
                int size;

                shortNameBuffer = new StringBuilder();
                size = GetShortPathName(longPathName, shortNameBuffer, shortNameBuffer.Capacity);
                
                if(size >= shortNameBuffer.Capacity)
                {
                    shortNameBuffer.Capacity = size + 1;
                    GetShortPathName(longPathName, shortNameBuffer, shortNameBuffer.Capacity);
                }
                
                return shortNameBuffer.ToString();
                

                }

                1 Reply Last reply
                0
                • V vuthaianh

                  Hi Evan, The ConnectionString i'm using to read *dbf files is "Provider=Microsoft.Jet.OLEDB.4.0; Data Source= " + directoryName + "; Extended Properties=dBASE IV; User ID=; Password=;"" My current solution is copying that DBF file to temporary DBF file which has a legal name (length of filename <= 8), processing on the temporary file and deleting it after finishing. If you have a better solution, Please let me know. Thanks a lot.

                  E Offline
                  E Offline
                  Evan Stein
                  wrote on last edited by
                  #8

                  Your solution will work, though copying is extra effort. The solution I proposed is to get an 8.3 name from Windows. This name is a direct substitute for the long name of the file. It will have a tilde (~) character and a number in it, and can be used to access the DBF file you want. I've had the darndest time putting in the code, and have found that it's possible to put in when the code is by itself, without a message. Therefore, the code for the function is separate. Good luck. Evan

                  V 1 Reply Last reply
                  0
                  • E Evan Stein

                    Your solution will work, though copying is extra effort. The solution I proposed is to get an 8.3 name from Windows. This name is a direct substitute for the long name of the file. It will have a tilde (~) character and a number in it, and can be used to access the DBF file you want. I've had the darndest time putting in the code, and have found that it's possible to put in when the code is by itself, without a message. Therefore, the code for the function is separate. Good luck. Evan

                    V Offline
                    V Offline
                    vuthaianh
                    wrote on last edited by
                    #9

                    Thanks Evan, this helps me much

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups