Wednesday, November 24, 2010

Send HTML Content As Mail using Lotus Script

The following function will help you send html content as a mail

Function sendHTMLContentAsMail(recipients As Variant,ccTo As Variant,bccTo As Variant, _
Subject As String,bodyHtmlContent As String)
'Declare Variables 
Dim s As New NotesSession
Dim db As NotesDatabase
Dim body As NotesMIMEEntity
Dim stream As NotesStream
Dim host As String
Dim message As  NotesDocument 

On Error Goto errHandler

Set db = s.CurrentDatabase
Set message=db.CreateDocument
'Capture the server name and filepath for use in URLs
Dim ServerName As New NotesName( db.Server )
host = "http://" + ServerName.Common & ".com"

s.ConvertMIME = False ' Do not convert MIME to rich text
Set stream = s.CreateStream
Set body = message.CreateMIMEEntity
message.Subject =Subject
message.SendTo =recipients
message.CopyTo =ccTo
message.BlindCopyTo =bccTo
message.RecNoOutOfOffice = "1"   
Call stream.WriteText (bodyHtmlContent)
' Ensure the MIME content will be recognized as HTML   (Must be after the stream is written)
Call body.SetContentFromText (stream, "text/html;charset=iso-8859-1", ENC_NONE) 
Call message.Send (False)  

s.ConvertMIME = True ' Restore conversion
Exit Function
Msgbox Error,,Cstr(Erl)
Exit Function
End Function

Hope this helps :)

Tuesday, November 23, 2010

Lotusscript code to append hotspot to a richtext field

My aim is to append a Link hotspot to the rich text field of a notes document as illustrated in the following image on a button click

The following code helped me perform the same
Function AppendHotspotLink (rtitem As NotesRichTextItem, url As String) As String
'** This function will attempt to append a button to a given
'** NotesRichTextItem, using code that has been assigned
'** to this object after it has been created (using the SetCode
'** method). The code language (as set with the SetLanguageType
'** method) can be either LotusScript or Formula language.

'** If there is an error creating the button (often because the code
'** doesn't compile correctly), this function will return the error
'** message. If the button is created properly, an empty string
'** will be returned.
On Error Goto processError

'** if no rich text item was given to us, just exit without doing anything
If (rtitem Is Nothing) Then
Exit Function
End If

Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim body As NotesRichTextItem
Dim importer As NotesDXLImporter

Dim buttonCode As String
Dim buttonTag As String
Dim dxl As String

'** set up the DXL to be used for the code in the button
If (buttonLanguage = RTB_LOTUSSCRIPT) Then
buttonCode = |<lotusscript>Sub Click(Source As Button)
| & XmlConvert(code) & |
End Sub</lotusscript>|
buttonCode = |<formula>| & XmlConvert(code) & |</formula>|
End If

buttonTag = |<button width='2in' widthtype='fitcontent' wraptext='true' |
If (edgeType = RTB_SQUARE) Then
buttonTag = buttonTag & | edge='square' |
buttonTag = buttonTag & | edge='rounded' |
End If
buttonTag = buttonTag & | bgcolor='system'>|

'** DXL that will create a temporary doc with the button we want.
'** We're adding the current user name in an Author field on
'** this temporary document because we'll be deleting it at the end
'** of this function, and the user may only have Author access to
'** this database.
dxl = |<?xml version='1.0' encoding='ISO-8859-1'?>
<!DOCTYPE document SYSTEM 'xmlschemas/domino_8_5.dtd'>
<document xmlns='' version='8.5.1'
 replicaid='0123456789ABCDEF' form='ButtonMaker'>
<item name='DocAuthor' authors='true' names='true'>
<text>| & XmlConvert(session.CommonUserName) & |</text></item>
<item name='Body'><richtext>
<pardef id="1" />
 <par def="1">
<code event="click">
  <formula>@URLOpen("|& url &|")</formula>
  Document Link

'** create a new doc using the DXL above
Set db = session.CurrentDatabase
Set importer = session.CreateDXLImporter(dxl, db)
importer.ReplicaRequiredForReplaceOrUpdate = False
importer.DocumentImportOption = DXLIMPORTOPTION_CREATE
Call importer.Process

'** get the button from the doc we just created and append it to
'** the rich text item we were given
Set doc = db.GetDocumentByID(importer.GetFirstImportedNoteId)
Set body = doc.GetFirstItem("Body")
Call rtitem.AppendRTItem(body)

'** try to delete the temporary doc. In case we can't delete it for some
'** reason, a scheduled agent should be written to globally delete
'** docs that use the form name specified in the DXL above.
On Error Resume Next
Call doc.RemovePermanently(True)

Exit Function

If (importer.Log <> "") Then
AppendHotspotLink = importer.Log
AppendHotspotLink = "Error " & Err & " on line " & Erl & ": " & Error$
End If
Exit Function
End Function

Function XmlConvert (txt As String) As String
'** get rid of the text characters that XML doesn't like (accented
'** characters are usually okay, as long as you use an encoding
'** like ISO-8859-1
XmlConvert = txt
XmlConvert = Replace(XmlConvert, "&", "&amp;")
XmlConvert = Replace(XmlConvert, "<", "&lt;")
XmlConvert = Replace(XmlConvert, ">", "&gt;")
End Function

Note: Use the following code to test the above function


Dim session As New NotesSession
Dim doc As NotesDocument
Dim rtitem As NotesRichTextItem

Dim result As String

'** grab the first selected doc in the view
Set doc = session.CurrentDatabase.UnprocessedDocuments.GetFirstDocument
Set rtitem = doc.GetFirstItem("Body")
If (rtitem Is Nothing) Then
Set rtitem = New NotesRichTextItem(doc, "Body")
End If

Call AppendHotspotLink(rtitem,"")

'** save and exit
Call doc.Save(True, True)

%end rem

Wednesday, November 10, 2010

get Current Folder Path in Java

The following function helps you get the current folder path of your project

public String getCurrentFolderPath() {
String path = "";
try {
path = new".").getCanonicalPath();
} catch (IOException e) {
// TODO Auto-generated catch block
} finally {
return path;

Hope this helps :)

CopyDirectory Function in Java

The following function will help you copy a directory from one location to an other.I got this good function with the help of my friend google :)

public void copyDirectory(File sourceLocation , File targetLocation)
   throws IOException {
       if (sourceLocation.isDirectory()) {
           if (!targetLocation.exists()) {
           String[] children = sourceLocation.list();
           for (int i=0; i<children.length; i++) {
               copyDirectory(new File(sourceLocation, children[i]),
                       new File(targetLocation, children[i]));
       } else {
           InputStream in = new FileInputStream(sourceLocation);
           OutputStream out = new FileOutputStream(targetLocation);
           // Copy the bits from instream to outstream
           byte[] buf = new byte[1024];
           int len;
           while ((len = > 0) {
               out.write(buf, 0, len);


                File source=new File("c:\\ak");
File target=new File("c:\\bk");
try {
} catch (IOException e) {
// TODO Auto-generated catch block

Hope this helps :)

Tuesday, November 9, 2010

Setting up Offline Password in Domino Quickr

In order for a user to go offline in Quickr-D, his/her offline password needs to be configured.

If in case a user proceeds further with out configuring a offline password he/she might experience the following error message when attempting to create a offline station in quickr-D
error requesting offline configuration from the server

To configure the offline password follow the following steps,
  • 1.       Open up the place which the user wants to go offline with
  • 2.       Go to the member’s section and open up the member profile

  •    Edit the Member profile by clicking the Edit button
  •    Scroll down and configure the offline password for the user and click next

Tuesday, November 2, 2010

Open Xpage from a Notes Form or View on Notes Client 8.5.1

In order to open a xpage ( say a document on a xpage) from a Notes Form or View from the notes client, use a button or a hot spot that contains a code fragment similar to the following,


Note the usage of the word openXPage in the query string. Ensure that it is present there, 'cos the XPage wont open up if it does not have this part in the url and instead it will open up the default view of the database instead.

Hope this Helps  :)

Monday, November 1, 2010

Setting "Do not locally Encrrypt" by default

Copying Databases into our local file system with encryption is one of the head ache in most of the times when u really dont want any security to be associated with the database being copies, example POCs etc

Setting this property is some thing that I use time and again and forget where I did it.

Hope the following piece of info helps people recollect this stuff.

-->choose File
-->User Security 
--> Notes Data 
--> Notes Databases 
--> select "Do not locally encrypt" 
--> click OK

It is as illustrated in the following image,