Manage Learn to apply best practices and optimize your operations.

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 
	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,True) 'needed for remove
				Set notesRichTextItem = New NotesRichTextItem( 
doc , )  '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 dui.refresh(True)

Dig Deeper on Domino Resources - Part 6



  • iSeries tutorials's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...