Manage Learn to apply best practices and optimize your operations.

Rename any attachment on a form

Rename attachments from forms.

This script allows you to rename any attachment on a form.

Code is line-wrapped to prevent horizontal scrolling

Sub Click(Source As Button)
	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	
	'Close document and reopen it using universal id
	Dim editmode As Variant 
	Call dui.Save 
	editmode = dui.Editmode 
	Call dui.Close 
	Set dui = wui.EditDocument( editmode, doc)
	
	
End Sub

Dig Deeper on Lotus Notes Domino Administration Tools

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com'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 ...

SearchDataCenter

SearchContentManagement

Close