Rename attachments
This script purpose is to enable user to rename attachments.
This script purpose is to enable user to rename attachments. Following the Lotuscript Doc it should work, and I guess it would work on some notes versions. I over commented the code so you can see where the big point is about version compability.
Dim wui As New notesuiworkspace Dim dui As notesuidocument Dim doc As notesdocument Set dui = wui.currentdocument If dui.isnewdoc Then Print "Only Rename saved documents , Save if before renaming" Exit Sub End If Set doc=dui.document Dim ret,pick,newname As Variant ret = Evaluate( { @AttachmentNames } , doc) pick = wui.Prompt( PROMPT_OKCANCELLIST, "Rename Attachment","Choose Attachment to rename", , ret ) newname =wui.Prompt( PROMPT_OKCANCELEDIT, "New Name","Choose the new name",Cstr(pick)) If (pick = "" Or newname="" )Then Exit Sub ' user canceled 'We grab the Attachment Dim attach,newattach As Notesembeddedobject Dim rtitem As Variant 'in case there are several attachments with the same name ' we need loop the richtextitem cause getattachment directly won't state us ' the field the file is in ' I could not find an easy way to rename 2 attachements of the same name in the ' same field ' but I wonder who needs that ;-) Forall i In doc.items Set rtitem = i If ( rtitem.Type = RICHTEXT ) Then Set attach = doc.GetAttachment(Cstr(pick)) 'I should have queried the registry here to 'get windows Temp dir but well you should had it yourself If Not(attach Is Nothing) Then Call attach.extractfile("c:" &Cstr(newname)) Call attach.remove 'here is the problem Call doc.save(True,True) 'needed for remove Set notesRichTextItem = New NotesRichTextItem( doc , rtitem.name ) 'don't ask me why simply it's needed Set newattach = rtitem.EmbedObject(1454, "", ("c:" &Cstr(newname))) 'reattach with new name Kill ("c:" &Cstr(newname)) End If Set attach = Nothing End If End Forall 'We try to save the Document and refresh it 'If this way of refreshing does not work for you , call a close doc , 'and reopen with Unid Call doc.save(True,True) Call dui.refresh(True)