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. Visual Basic
  4. PathTooLongException and Solutions?

PathTooLongException and Solutions?

Scheduled Pinned Locked Moved Visual Basic
helpcsharpquestionannouncement
4 Posts 2 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.
  • T Offline
    T Offline
    treddie
    wrote on last edited by
    #1

    Hi. I was reading the article: .NET 2.0 Workaround for PathTooLongException for a solution to the too long path name problem. In that article it states that there is a long, "W" version of the CreateFile() function. Now, the class he developed seems to support opening, reading and writing of files but not looking at the contents of a directory. I have two questions: 1. Is there an "easy" way to expand his class to include other functions such as listing directory contents? If so, what other functions would be required to pull this off? I have found such functions such as FindFirstFile(), but the documentation and Googling do not suggest that there are any "W" versions of these. UPDATE: According to MSDN, FindFirstFileEx() does not carry the MAX_PATH limitation, so in theory, it should work. 2. In his code, he does not include declarations for his API functions, although he does import namespaces. Is this because he is working in C# (which I am only partly familiar with)? I have converted his code from C# to vb.Net, but the online converter cannot necessarily know that declarations need to be added to the converted code, if in fact they DO need to be. My experience says, "Yes", it definitely does, but then again, why wouldn't those same Import lines work just as well in vb.Net? If that is where these functions are located, then why does vb.Net require explicit declarations? Is this so an entire library does not need to be loaded into memory all at once? Many thanks for any help! :) Below is his original code and usage, followed by my online conversion from C# to vb.Net:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using Microsoft.Win32.SafeHandles;
    using System.Runtime.InteropServices;
    using System.IO;

    namespace System.IO
    {
    class Win32File
    {

        // Error
        const int ERROR\_ALREADY\_EXISTS = 183;
        // seek location
        const uint FILE\_BEGIN = 0x0;
        const uint FILE\_CURRENT = 0x1;
        const uint FILE\_END = 0x2;
    
    
        // access
        const uint GENERIC\_READ = 0x80000000;
        const uint GENERIC\_WRITE = 0x40000000;
        const uint GENERIC\_EXECUTE = 0x20000000;
        const uint GENERIC\_ALL = 0x10000000;
    
        const uint FILE\_APPEND\_DATA = 0x00000004;
    
        // attribute
        const uint FILE\_ATTRIBUTE\_NORMAL = 0x80;
    
        // share
        c
    
    L 1 Reply Last reply
    0
    • T treddie

      Hi. I was reading the article: .NET 2.0 Workaround for PathTooLongException for a solution to the too long path name problem. In that article it states that there is a long, "W" version of the CreateFile() function. Now, the class he developed seems to support opening, reading and writing of files but not looking at the contents of a directory. I have two questions: 1. Is there an "easy" way to expand his class to include other functions such as listing directory contents? If so, what other functions would be required to pull this off? I have found such functions such as FindFirstFile(), but the documentation and Googling do not suggest that there are any "W" versions of these. UPDATE: According to MSDN, FindFirstFileEx() does not carry the MAX_PATH limitation, so in theory, it should work. 2. In his code, he does not include declarations for his API functions, although he does import namespaces. Is this because he is working in C# (which I am only partly familiar with)? I have converted his code from C# to vb.Net, but the online converter cannot necessarily know that declarations need to be added to the converted code, if in fact they DO need to be. My experience says, "Yes", it definitely does, but then again, why wouldn't those same Import lines work just as well in vb.Net? If that is where these functions are located, then why does vb.Net require explicit declarations? Is this so an entire library does not need to be loaded into memory all at once? Many thanks for any help! :) Below is his original code and usage, followed by my online conversion from C# to vb.Net:

      using System;
      using System.Collections.Generic;
      using System.Text;
      using Microsoft.Win32.SafeHandles;
      using System.Runtime.InteropServices;
      using System.IO;

      namespace System.IO
      {
      class Win32File
      {

          // Error
          const int ERROR\_ALREADY\_EXISTS = 183;
          // seek location
          const uint FILE\_BEGIN = 0x0;
          const uint FILE\_CURRENT = 0x1;
          const uint FILE\_END = 0x2;
      
      
          // access
          const uint GENERIC\_READ = 0x80000000;
          const uint GENERIC\_WRITE = 0x40000000;
          const uint GENERIC\_EXECUTE = 0x20000000;
          const uint GENERIC\_ALL = 0x10000000;
      
          const uint FILE\_APPEND\_DATA = 0x00000004;
      
          // attribute
          const uint FILE\_ATTRIBUTE\_NORMAL = 0x80;
      
          // share
          c
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      treddie wrote:

      In his code, he does not include declarations for his API functions, although he does import namespaces. Is this because he is working in C#

      He does. You can browse the source code using the links in the article. His P/Invokes start on line number 46.

      treddie wrote:

      the online converter cannot necessarily know that declarations need to be added to the converted code, if in fact they DO need to be.

      Bad translator.

      treddie wrote:

      why wouldn't those same Import lines work just as well in vb.Net? If that is where these functions are located, then why does vb.Net require explicit declarations? Is this so an entire library does not need to be loaded into memory all at once?

      There's multiple ways to link/load a dll. The "using" or "import" lines are defining which namespaces to look in when searching for a specific class-type. Sometimes one needs to "add (a) reference" to an external assembly to be able to access types in other libraries. That's the usual route for managed code - anything in .NET. There's also a lot of unmanged code on the machine, as is the WinAPI. The code is also linking to a specific part in the WinAPI in "kernel32.dll". Both VB.NET and C# need special declarations for these, decorated with the DllImport attribute.

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

      T 1 Reply Last reply
      0
      • L Lost User

        treddie wrote:

        In his code, he does not include declarations for his API functions, although he does import namespaces. Is this because he is working in C#

        He does. You can browse the source code using the links in the article. His P/Invokes start on line number 46.

        treddie wrote:

        the online converter cannot necessarily know that declarations need to be added to the converted code, if in fact they DO need to be.

        Bad translator.

        treddie wrote:

        why wouldn't those same Import lines work just as well in vb.Net? If that is where these functions are located, then why does vb.Net require explicit declarations? Is this so an entire library does not need to be loaded into memory all at once?

        There's multiple ways to link/load a dll. The "using" or "import" lines are defining which namespaces to look in when searching for a specific class-type. Sometimes one needs to "add (a) reference" to an external assembly to be able to access types in other libraries. That's the usual route for managed code - anything in .NET. There's also a lot of unmanged code on the machine, as is the WinAPI. The code is also linking to a specific part in the WinAPI in "kernel32.dll". Both VB.NET and C# need special declarations for these, decorated with the DllImport attribute.

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

        T Offline
        T Offline
        treddie
        wrote on last edited by
        #3

        Cool. Tank you very much for your help, Eddy.

        L 1 Reply Last reply
        0
        • T treddie

          Cool. Tank you very much for your help, Eddy.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          You're welcome :)

          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