Hai All, I have Attachment and when I will click on a button the attachment will save in Harddisk(c:,D:,etc)
Is It Possible
Please Guide me.
Hai All, I have Attachment and when I will click on a button the attachment will save in Harddisk(c:,D:,etc)
Is It Possible
Please Guide me.
Subject: How To Save A Attachment in Local Drive
Here is the code I have in a script library that does what you want. My code is part of a customized mail db, and looks to the calendar profile for a default path entered by the user. But you can simplify the code.
Sub DetachFiles
On Error Goto ErrorHandler
Dim strPath As String, strFilePath As String, strFile As String, strMsg As String, strDir As String
Dim rtitem As Variant, varFlag As Variant, varAns As Variant
Dim richstyle As NotesRichTextStyle
Dim x As Integer, intAction As Integer
Dim arsFiles() As String, arsActions(0 To 1) As String
Set session = New NotesSession
Set ws = New NotesUIWorkspace
Set db = session.CurrentDatabase
Set uidoc = ws.CurrentDocument
Set doc = uidoc.Document
Set rtitem = doc.GetFirstItem("Body")
If Not (doc.HasEmbedded) Then
Msgbox "There are no file attachments on this document"
Goto ExitRoutine
End If
'Get default file location from profile doc
Set profdoc = db.GetProfileDocument("CalendarProfile")
strDir = profdoc.DetachFilePath(0)
'Prompt user for location to detach file to
varFlag = ws.Dialogbox("FileLocPrompt", True, True, False, False, False, False, "Detach Files To . . .", doc, True, False)
strDir = doc.FileDirectory(0)
If Not(varFlag) Then
Goto ExitRoutine
End If
'Check if the directory exists
strPath = Dir$(strDir, 16)
If strPath = "" Then
strMsg = "Specified directory does not exist. Would you like to create is now?"
intAction = Msgbox(strMsg, MB_YESNO + MB_ICONINFORMATION, "Invalid Path")
If intAction = IDYES Then
Mkdir strDir
Else
Goto ExitRoutine
End If
End If
'Detach the file to the directory specified by the user
Forall o In rtitem.EmbeddedObjects
If o.Type = EMBED_ATTACHMENT Then
strFile = o.Source
strFilePath = strDir & "\" & strFile
'Check if the filename already exists in the directory. If the filename already exists, prompt the user
strPath = Dir$(strFilePath, 0)
If strPath <> "" Then
strMsg = "A file with the name " & strFile & " already exists. Choose an option from the list below"
arsActions(0) = "1. Overwrite the existing file"
arsActions(1) = "2. Keep the existing file and save the new file with a different name"
varAns = ws.Prompt(PROMPT_OKCANCELLIST, "", strMsg, arsActions(0), arsActions())
If varAns = "" Then
'If the user clicks Cancel, exit
Goto ExitRoutine
Elseif Left$(varAns, 1) = "2" Then
'If the user chooses option 2, prompt the user for a new name for the file
strMsg = "Enter a new name for the file"
varAns = Inputbox(strMsg, "New Filename", strFile)
If varAns = "" Then
'If the user clicks Cancel, exit
Goto ExitRoutine
Else
'Convert the variant to a string
strFile = Cstr(varAns)
strFilePath = strDir & "\" & strFile
End If
End If
End If
'Extract the attachment to the file directory & remove it from the Notes doc
Call o.ExtractFile(strFilePath)
Call o.Remove
'Store each file path to an array
Redim Preserve arsFiles(0 To x)
arsFiles(x) = strFile
x = x + 1
End If
End Forall
'Append file attachment info to Body field of original mail memo
Set richstyle = session.CreateRichTextStyle
Call rtitem.AddNewLine(1)
richstyle.NotesColor = COLOR_RED
Call rtitem.AppendText("*********************************************************************************")
Call rtitem.AddNewLine(1)
Call rtitem.AppendText("File attachments for this document have been detached to " & strDir)
Call rtitem.AddNewLine(2)
Call rtitem.AppendText("File List:")
Call rtitem.AddNewLine(1)
For x = 0 To Ubound(arsFiles)
Call rtitem.AppendText(arsFiles(x))
Call rtitem.AddNewLine(1)
Next x
'Store the file path on the mail memo doc
doc.FilePath = strDir & "\"
doc.FileNames = arsFiles
'Set $ContentIcon field so the information icon will show in column in Inbox
Call doc.ReplaceItemValue("$TypeIcon", 11)
Call doc.Save(False, True)
Call uidoc.Close
Call ws.ViewRefresh
ExitRoutine:
Exit Sub
ErrorHandler:
strMsg = "An error occurred while attempting to detach the file(s) -- " & Error$
Msgbox strMsg, MB_OK + MB_ICONINFORMATION
Resume ExitRoutine
End Sub
Subject: How To Save A Attachment in Local Drive
use the method extractfile of the notesembeddedobject class.
note: if the agent is running on the server, this file will get extracted on the servers hard disk.