Hi There,
I have an agent that downloads attachments from Notes Documents, retaining the filename (fair enough).
However, I would like to change the filename to the Document Number of the Notes Document. The agent uses the Filename to get the attachment, but once it gets the attachment, is there a way i can rename the file?
Thanks
F1H
Code Snippet :
For i =1 To theDocuments.Count
Set theDocument = theDocuments.ItemByIndex(i-1)
' Downloads the current document's file attachment.
FileName = Path+ "\" + theDocument.Filename
Call theDocument.GetContents(FileName)
Next
Subject: Rename File
Look at the Name statement in Designer Help.
Subject: RE: Rename File
Brilliant!
Thanks Stan, once again, you have helped me!
F1H
Subject: Rename File — Small Problem
Hi,
Trying to rename a file, but it is saying it can find the file. It is definately there (allbeit just created)
Code :
For i =1 To theDocuments.Count
Set theDocument = theDocuments.ItemByIndex(i-1)
' Downloads the current document's file attachment.
FileName = Path+ "\" + theDocument.Filename
Call theDocument.GetContents(FileName)
'Name "C:\WINDOWS\TEST1" As "C:\TEST2"
Name Path+ "\" + theDocument.Filename As Path+ "\" + FDoc.DocumentNumber(0) ' ERROR HERE
Next
Not sure if i need extra quotes around the file paths or if there is a performace problem (file is not there quick enough for me to rename it)?
Thanks for any help.
Subject: RE: Rename File — Small Problem
I’d suggest that timing is probably the problem. You could try sleeping for a short time, or (and I’m not familiar with the method – is it from an LSX?) waiting for a result from the GetContents call if one is available.
Subject: RE: Rename File — Small Problem
Hi Stan,
Thanks for that, it was actually due to the API for DOmino.Doc not holding the DocumentNumber or something - working now, but i am getting a permission Denied error when trying to rename my second document, think it may be something to do with my FOR loop, but i am not sure.
anyone help me with this?
Thanks
F1H
P.S. Apologies for the double post
Code :
Sub Initialize
Dim Session As New NotesSession
Dim db As NotesDatabase
Dim Docs As NotesDocumentCollection
Dim Binder As notesDocument
Dim Doc As NotesDocument
Dim FDoc As NotesDocument
Dim item As notesItem
Dim Proyect As Variant
Dim Number As Variant
Dim unid As String
Dim Contador As Integer
Dim Path As String
Dim DocNum As String
On Error Goto processError
'Create the Api object
Set theApi = CreateObject("DominoDoc.API")
'Get the Cabinet
Set db = session.CurrentDatabase
Set Docs = db.Unprocesseddocuments
Set Binder = Docs.GetFirstDocument
Set FDoc = Docs.GetFirstDocument
'Get Library
Set theLibrary = theApi.GetLibrary("notes://pmpgla5/domdoc/BusinessSystemsTestLib.nsf")
'Get the Cabinet
Set theCabinet = theLibrary.Cabinets("eStandards")
unid = thecabinet.UniversalId
Contador = 0
'Get the collection of binders
While Not Binder Is Nothing
' Define Path
Path = "C:\DomDocExport\QA\"
'The API used the Binder made up of the Cabinet + ID of the Binder
Set theBinder = thelibrary.GetBinderById(unid+Binder.BinderId(0))
Set theDocuments = theBinder.Documents
If theDocuments.Count > 0 Then
Path = Path + Binder.Title(0)
'Create the necessary directory for placing the document
Directory$ = Path
TempDir = CreateDir()
If TempDir = False Then 'Directory could not be created
Messagebox "Directory C:\DomDocExport\QA\ not available."
Exit Sub
End If
For i =1 To theDocuments.Count
Set theDocument = theDocuments.ItemByIndex(i-1)
' Downloads the current document's file attachment.
FileName = Path+ "\" + theDocument.Filename
Call theDocument.GetContents(FileName)
'If the Document number contains slashes (not allowed in file names, then replace with the proper -
If Instr(FDoc.DocumentNumber(0),"/") Then
DocNum = Replace(FDoc.DocumentNumber(0),"/","-")
End If
Name Path & "\" & theDocument.Filename As Path & "\" & DocNum & Right(theDocument.Filename,4)
Next
End If
Contador = Contador + 1
Print "Processing " + Cstr(Contador) +" of "+ Cstr(Docs.Count)
Set FDoc = Docs.GetNextDocument(FDoc)
Set Binder = Docs.GetNextDocument(Binder)
Wend
Messagebox "All documents processed correctly.", MB_OK + MB_ICONEXCLAMATION, "Domino.Doc Aplication"
Exit Sub
processError:
Messagebox Error$, MB_OK + MB_ICONEXCLAMATION, "Domino.Doc API Error"
' Errors will be reported via the OpenDatabase UI
Exit Sub
End Sub
Subject: RE: Rename File — Small Problem
If this is truely Domino.doc that is the issue… Check that you have DOMINO.DOC manager\editor right all the way do the DOMINO.DOC structure. You have to be manage to the parent above to be manager below etc.
This is a huge issue with Domino.doc security. The reason I have added DOMINO.DOC in caps is because it does not abide by Domino standard rules.
So check the user you are logged into DOMINO.DOC has the correct permissions and try again.