Question

I'm receiving feedback from a developer that "The only way visual basic (6) can deal with a UNC path is to map it to a drive." Is this accurate? And, if so, what's the underlying issue and are there any alternatives other than a mapped drive?

Was it helpful?

Solution

Here is one way that works.

Sub Main()

    Dim fs As New FileSystemObject ' Add Reference to Microsoft Scripting Runtime
    MsgBox fs.FileExists("\\server\folder\file.ext")

End Sub

OTHER TIPS

We have a legacy VB6 app that uses UNC to build a connection string, so I know VB6 can do it. Often, you'll find permissions problems to be the culprit.

Even the old school type of file handling does work:

Open "\\host\share\file.txt" For Input As #1
Dim sTmp
Line Input #1, sTmp
MsgBox sTmp
Close #1

I don't think this is True, if you are using the Scripting.Runtime library.

Oldschool VB had some language constructs for file handling. These are evil. Don't use them.

In VB6 you cannot use CHDrive to a UNC path.

Since App.Path returns a UNC path, attempting to use ChDrive to this path, ChDrive App.Path will cause an error.

As Microsoft say "ChDrive cannot handle UNC paths, and thus raises an error when App.Path returns one". For more information, look at http://msdn.microsoft.com/en-us/library/aa263345(v=vs.60).aspx

What sort of file I/O are you doing? If it's text, look into using a FileSystemObject.

I have observed VB6 UNC path issues when a combination of the items below exist:

  • the unc points to a hidden '$' share
  • the server name exceeds 8 chars and or has non standard chars
  • a portion of the path is exceptionally long
  • the server has 8.3 support turned of for performance purposes

Usually a 75 path file access error or 54. At times this may be related to API's such as getshortfilename and getshortpathname on the aforementioned UNC's.

Other than that they work great... A mapped path will usually not have these issues but those darned drive mappings disconnect often and can change at anytime causing many support headaches.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top