Problem with Folderitem.Exists

WIN 7 Ultimate

My application runs locally but accesses a shared data file on the network. I allow the user to select the location of the shared data file by using the SelectFolderDialog. It appears I am having an issue with “shared” folders using UNC e.g. \\Server\Shareddata\.

In the SelectFolderDialog it allows the user to select the shared folder (The OK button is enabled when the folder is selected in the tree). However if I do a folderitem.exists after the item is selected it returns false. BUT if I select a subdirectory of the shared folder it comes back as true. Also, if I map the “share” to a drive it works perfectly and if I type the path into windows explorer address bar it does show as valid.

Here is a simplified version of the code:

[code] Dim dlg as New SelectFolderDialog
Dim f as FolderItem
dlg.InitialDirectory=SpecialFolder.Documents
f=dlg.ShowModal()

If f <> Nil then

If f.Exists Then
  MsgBox "Success: " + F.AbsolutePath
Else 
  MsgBox "does not exist"
  Return
End If

else
MsgBox “Nil”
Return
end if[/code]

(I know absolute path is deprecated, but this is some older RS code, but performs the same in Xojo. However, if you mouse over the “Exists” property in the LR it has a popup bubble that references Absolute Path - this might need updating Paul)

What mechanism does the SelectFolderDialog utilize to allow selection of a folder (valid or invalid)? The OK button is disabled when opened and when selecting invalid folders (i.e. computer), but becomes enabled once you drill down.

Ideas? Thanks!

I think I may know what’s happening so hold on tight as it gets a bit technical (and maybe wrong).

In essence, the appearance of a shared folder on a network drive is not a real folder. It is, in essence, a connection point (there is an actual name for it but I can’t recall what it is) and serves only as a virtual connection to what is “inside” it on the network. By selecting something inside the shared network folder, you are connecting to an actual thing so the code works.

Similarly, by mapping the connection point to a drive you are giving it a “real” identity and it can therefore be seen as a real thing.

Since the shared network folder isn’t a real folder, it will return false for the .Exists call. The proper solution is, as you stated, to map it to a local drive (and be sure to unmap it when the application exits or the connection is no longer needed.)

WFS has a chunk of code to make it so you can map & unmap the drive in code

Dale, I think what you are describing is accurate and it behaves exactly that way. If I select a sub folder in the “share” it works fine. The short term solution is to move everything that is in the base level of the share to a subdirectory.

Norman, my concern is the behavior of the SelectFolderDialog. It looks like it is capable of discerning “some” of the differences between valid folders and invalid folders. It enables or disables the “OK” button in the dialog based on the selection.

However it does look like it is allowing the selection of items that don’t exists OR at least folderitem.exists reports as doesn’t exist. So either folderitem.exists is reporting false when it is true or the logic in the SelectFolderDialog is not solid. If I had to guess, I would say it is an issue with folderitem.exists, since you can actually paste the return value of the dialog into explorer and it actually locates it properly. Do you think this is a bug?

Possibly a folderitem bug as the selection dialog is, as far as I know, the system provided one not something custom

Yes, it is :slight_smile:

Here’s a Feedback about this issue, including a workaround in the example project: <https://xojo.com/issue/38665>
And here’s another Thread about this: UNC path and folderitem - Windows - Xojo Programming Forum