Select Folder - with default Folder

Hi AllI have a problem :slight_smile: I wrote a script to select a folder. The script is working quite fine (see below).

But i’d like to set a default folder, the one he select at the last time. I found some solutions in the web. Most of them for VB. The Problem is that, all work with “adressof” and this doesen’t exist in LS.

VB Example: Frequently Asked Questions - vbCity - The .NET Developer Community

Thanks and greetings from switzerland…

Well and here is my Script:

Declarations:

%INCLUDE “lsconst.lss”

%REM

These declarations are in support of the MSWindows APIs that are used by this

agent. This means that this agent will only work on Win32 clients.

%END REM

Type BROWSEINFO

hwndOwner As Long

pidlRoot As Long

pszDisplayName As String

lpszTitle As String

ulFlags As Long

lpfn As Long

lParam As Long

iImage As Long

Hwnd As Long

End Type

Const BIF_RETURNONLYFSDIRS = &H1

Const BIF_DONTGOBELOWDOMAIN = &H2

Const BIF_STATUSTEXT = &H4

Const BIF_RETURNFSANCESTORS = &H8

Const BIF_EDITBOX = &H10

Const BIF_VALIDATE = &H20

Const BIF_NEWDIALOGSTYLE = &H40

Const BIF_USENEWUI = (BIF_NEWDIALOGSTYLE Or BIF_EDITBOX)

Const BIF_BROWSEINCLUDEURLS = &H80

Const BIF_UAHINT = &H100

Const BIF_NONEWFOLDERBUTTON = &H200

Const BIF_NOTRANSLATETARGETS = &H400

Const BIF_BROWSEFORCOMPUTER = &H1000

Const BIF_BROWSEFORPRINTER = &H2000

Const BIF_BROWSEINCLUDEFILES = &H4000

Const BIF_SHAREABLE = &H8000

Const MAX_SIZE = 260

'Const CSIDL_DRIVES = &H11

Public Const ADX_FOLDER_LOCATION = “adx_swf_folderloc”

Declare Function SHGetPathFromIDList Lib “shell32.dll” Alias “SHGetPathFromIDListA” (Byval pidl As Long, Byval pszPath As String) As Long

Declare Function SHBrowseForFolder Lib “shell32.dll” Alias “SHBrowseForFolderA” (lpbi As BROWSEINFO) As Long

Declare Sub CoTaskMemFree Lib “ole32.dll” (Byval pv As Long)

Sub Initialize

Dim session As New NotesSession

Dim wsp As New NotesUIWorkspace

Dim db As NotesDatabase

Set db = session.CurrentDatabase



Dim Message As String	

Dim BoxType As Long



Dim attachFolder As String



Exit Sub



' Ensure we are using windows 32

If session.Platform <> "Windows/32" Then

	Message = "Dieser Agent funktioniert nur auf einer Windows/32 Platform."

	BoxType = MB_OK+MB_ICONEXCLAMATION

	Messagebox Message, BoxType, "Warning"

	Exit Sub

End If



' Get the folder to attach PDFs

attachFolder = GetAttachFolder()

If Len(attachFolder) < 2 Then

	Message = "Es wurde kein Ordner gewählt. Der Import wird abgebrochen."

	BoxType = MB_OK+MB_ICONSTOP

	Messagebox Message, BoxType, "Warning"

	Exit Sub

'Else

	'check the existance of the current folder, if it doesn't exist, prompt.

'	If PathExists(attachFolder) Then

'		Message = "Der gewählte Ordner " + attachFolder + " existiert nicht."

'		BoxType = MB_OK+MB_ICONSTOP

'		Messagebox Message, BoxType, "Warning"

'		Exit Sub

'	End If

End If

Call session.SetEnvironmentVar( ADX_FOLDER_LOCATION, attachFolder )	'save strDetachFolder in to .ini



AttachPDF(attachFolder+"\*.pdf")

End Sub

Function GetAttachFolder() As String

Dim bi As BROWSEINFO  ' structure passed to the function

Dim pidl As Long  ' PIDL to the user's selection

Dim physpath As String  ' string used to temporarily hold the physical path

Dim retval As Long  ' return value

Dim vbNullChar As String

vbNullChar = Chr(0)





' Initialize the structure to be passed to the function.



bi.hwndOwner = 0 ' The owner of the dialog box.

bi.pidlRoot	 = 0

bi.pszDisplayName = Space(MAX_SIZE) ' Make room in the buffer to get the [virtual] folder's display name.

bi.lpszTitle = "Bitte Ordner wählen."	' Message displayed to the user.



bi.ulFlags = BIF_RETURNONLYFSDIRS

bi.lpfn = 0

bi.lParam = 0

bi.iImage = 0



' Open the Browse for Folder dialog box.

pidl = SHBrowseForFolder(bi)



If pidl <> 0 Then	' If the user selected something, display its display name and its physical location on the system.

	'Remove the empty space from the display name variable.		

	bi.pszDisplayName = Left(bi.pszDisplayName, Instr(bi.pszDisplayName, vbNullChar) - 1) 

	

      'If the folder is not a virtual folder, display its physical location.

	physpath = Space(MAX_SIZE)  'create a buffer

	retval = SHGetPathFromIDList(pidl, physpath) ' now get the selected path

	

	If retval = 0 Then

		Print "Physical Location: (virtual folder)"

	Else

           'Remove the empty space and display the result.

		physpath = Left(physpath, Instr(physpath, vbNullChar) - 1)

		Print "Physical Location: " + physpath

	End If

	

	CoTaskMemFree pidl

End If





 ' Whether successful or not, free the PIDL which was used to identify the My Computer virtual folder.

CoTaskMemFree bi.pidlRoot

GetAttachFolder = physpath ' Return the physpath value

End Function

Subject: Select Folder - with default Folder

Can you write the last-selected folder’s name to a profile field or the user’s Notes.INI file and retrieve it from there ?

Subject: RE: Select Folder - with default Folder

Thanks for the answer. BUT:Sure I can do that. But the problem is, that the Win32 API needs the Folder as Type “Long”. See “bi.pidlRoot = 0”. The challenge is to get the long-value of a folder.

Thanks

Subject: RE: Select Folder - with default Folder

Hi !I have the same need, have you found a solution or turn-around since ?

Thank you to share it.

Regards from Swizerland !