Allow User to specify where to save a file

I’ve written a LotusScript action button code that will generate an inventory list and save the results to a .CSV file. I want to be able to allow the user to specify where they want to save the .CSV file on their hard drive.

I’m trying to use the SaveFileDialog, but it doesn’t save the file where I specify. Close fielnum% seems to always put the file in the C:\ directory. I’ve also tried setting the file_directory var to “C:\Desktop” but it still puts the file in the C:\ directory.

How do I get it to save the file where I specify?? Thanks for any help.

Here is my code:

Sub Click(Source As Button)

'--------------------------------------------------------------------------------------

’ FUNCTION : User requested Customer Inventory Report in .CSV format

’ ACCESS : Action Button

’ VERSION : 1.7g

’ DESCRIPTION:

’ RETURN TYPE: Success/continue

'--------------------------------------------------------------------------------------

Dim workspace As New NotesUIWorkspace

Dim session As New notesSession

Set db=session.CurrentDatabase



Set view=db.GetView ("viewByCust")



Set maildoc = New NotesDocument( session.CurrentDatabase )

Set rtitem = New NotesRichTextItem( maildoc, "Body" )



file_directory = "C:\"

fileNum% = Freefile()

fileName$ = "Customer Inventory Report.csv"



 'Check to see if the file already exists

find_file = Dir$(file_directory & fileName$, 0)

'if not found, Create it and set value to zero

If find_file = "" Then

	fileNum%  = Freefile()

	filename1 = file_directory & fileName$	

	Open filename1 For Output As fileNum%

	

	'Write Header line

	headerline = "Customer Name,Team Name,Platform Name,System/Node Names,Server Location,User ID,"+_

	"Description,Password Owner,Last Revalidation Date,Check In/Out Required,Force PW Change,"+_

	"Groups,Authorized User"

	Print #fileNum%, headerline

	Close fileNum%

Else

	'delete any previous file

	Kill file_directory & fileName$

	

	'Create a new file

	fileNum%  = Freefile()

	filename1 = file_directory & fileName$	

	Open filename1 For Output As fileNum%

	

	'Write Header line

	headerline = "Customer Name,Team Name,Platform Name,System/Node Names,Server Location,User ID,"+_

	"Description,Password Owner,Last Revalidation Date,Check In/Out Required,Force PW Change,"+_

	"Groups,Authorized User"

	Print #fileNum%, headerline

	Close fileNum%

End If



WhichCust = Inputbox("Enter the Customer Name for this report.", db.Title)



j = view.FTSearch( WhichCust, 0 )

Set doc = view.GetFirstDocument()

Open file_directory & fileName$ For Append As fileNum%

For i = 1 To j-1		

	Set pwoname=New notesname(doc.PasswordOwner(0))

	LastRevalDate = Cstr(doc.LastUserIdAccessRevalPeriod(0))

	RequireCheckin= Cstr(doc.RequireCheckin(0))

	ForcePWchange = Cstr(doc.ForcePWchange(0))

	

	Set HoldList=doc.GetFirstItem("AllReaders")

	x=1

	Forall v In HoldList.values()

		Set usr = New NotesName (v)

		holdusr=usr.Abbreviated

		If x = 1 Then

			AuthReaders=holdusr

		Else

			AuthReaders=AuthReaders+","+holdusr

		End If

		holdusr = ""

		x=x+1

	End Forall

	

	txtline = doc.Customer(0)+","+doc.System_Organisation(0)+","+doc.System_PlatformName(0)+","+_

	doc.System(0)+","+doc.System_ServerLocation(0)+","+doc.Userid(0)+","+doc.Description(0)+","+_

	pwoname.Abbreviated+","+LastRevalDate+","+RequireCheckin+","+ForcePWchange+","+_ 

	doc.Type_1(0)+","+AuthReaders

	Print #fileNum%, txtline

	i=i+1

	Set doc = view.GetNextDocument(doc)

Next

'---------------------------------------

 REM Get filename from user

filenames =workspace.SaveFileDialog( True , "Save As" , "*.CSV" , "C:\" , fileName$ )

If Not(Isempty(filenames)) Then

      REM Write Body item to file

	fileNum% = Freefile()

	Open fileName$ For Output As fileNum%

	Print #fileNum%, maildoc("Body")(0)

	Close fileNum%

End If

'----------------------------------------

Msgbox "The " + fileName$ + " file has been saved.",0+64,db.Title

End Sub

Subject: Allow User to specify where to save a file

Use the following code -

    Dim ws As New NotesUIWorkspace

Dim filenames As Variant

Dim filenum As Integer



filenames = ws.SaveFileDialog( _

False,"File name",, "c:\Test", "Body.txt")

If Not(Isempty(filenames)) Then

  REM Write Body item to file

	fileNum% = Freefile()

	Open filenames(0) For Output As fileNum%

            'file contents here....

	Print #fileNum%, "Sample text"

	Close fileNum%

End If

All you have to do is to replace filename1 with filenames(0) and remove “file_directory” as its not required.

Try to run the above code to understand what it does.

–Phani

Subject: Allow User to specify where to save a file

You aren’t working with a temporary or in-memory file, but with a file you have actually created on disk. In order to put the file where the user wants it, you need to copy the file to the new location, rename it if necessary, then kill the original.