Automount a network path

Hi,
i’ve a problem reaching a file over a network path.
here is the code :

#if TargetWin32 then
   pdf.Image("N:\\Template_Invoice.png",0,0,210,0)
#elseif TargetMacOS then
   pdf.Image("/Volumes/SHARE/Template_Invoice.png",0,0,210,0)
#endif

This code crash if SHARE is not already mounted under Volumes. Is there a way to automount the network path SHARE refer to when my program start ?

Maybe a problem in the PDF handling classes you use?
Doesn’t look like my MBS DynaPDF Plugin.

No way that I know of, but you could check for N: not being available and create a shell to map the drive, something like:

Dim f As FolderItem = GetfolderItem("N:") If f = Nil Then Dim sh As New Shell sh.Mode = 0 sh.Execute("NET USE N: <share path>") End If

Untested code.

... #elseif TargetMacOS then dim f as folderitem = GetFolderItem("/Volumes/SHARE/Template_Invoice.png") if f.Exists then pdf.Image("/Volumes/SHARE/Template_Invoice.png",0,0,210,0) end if #endif

With a little more protection :slight_smile:

...
#elseif TargetMacOS then
dim fTest as FolderItem = SpecialFolder.Mount // How you're *really* supposed to get /Volumes according to the docs

try
  fTest = fTest.Child("SHARE").Child("Template_Invoice.png")
  if fTest.Exists = true then
    pdf.Image(fTest.NativePath, 0, 0, 210, 0)

  else
    // At this point the Volume is mounted, but the file doesn't exist
    // Handle error as you see fit.

  end

catch e as NilObjectException
  // Either the volume isn't mounted OR the /Volumes/SHARE folder doesn't exist

end try

#endif

(written in post editor)

I’d also check for readability and not being a directory:

if fTest.Exists and fTest.isReadable and not fTest.directory then