Automatically reattach after modification of an attachment - Part I

This script gives your databases the functionality to detach / edit / attach an attachment with one single click. Part I

This is Part I of script that gives your databases the functionality to detach // edit // attach an attachment with one single click.
Here is a downloadable sample database.
'CLASSAttachment: 

Option Public
%REM

19.08.2000:

2 new functions are added
   - Public Function RenameFile(SourceFile As String, DestFile As String, AFlag As Integer) As Long     
   - Private Function ReplaceSubstring(sSource As String, sFrom As String, sTo As String) As String     

Stuart Blake/TOWER/LondonStockEx@LondonStockEx reported the following:
    
    > I've tried this on a Word document with spaced in the filename, and
    > it doesn't like it.  if, for example, I try to launch a file called "Filename
    > With Spaces.doc", Word is activated correctly but then I get the message "Word
    > can not open the document: (C:TEMPFILENAME.DOC)".

Before opening the file with spaces in filename the file is now temporarily renamed and all spaces are replaced by "_" (underscore).
When reattaching, the file is renamed to its original filename

SIDE-EFFECT: 

The "IsModified"-flag is alsways set to TRUE, even if there is no modification in the file itself.

================

19.08.2000

The  FindExecutable - Function did not work under Win2000.
In case of DOC and XLS suffix, executables are now retrieved from the Windows registry

Added new method :

    Public Sub Modify ( AttName As String , InItem As String )   

24.08.2000

Added New function "GetShortFileName"

We always use the short FileName when launching it with an application.
We do not need to rename the file before launching.
This also fixes the bug reported by Stuart Blake 19.08.2000.
The functions added on 19.08.2000 are removed.

Added registry search for "MSProject98"

No value was returned, when calling the FindExecutableByExtension-function with ".mpp" suffix.
We use registry settings instead.

25.08.2000 

PopMenu integrated in script library

03.09.2000

Sub CreateFromTemplate added

09.09.2000

There seem do be a problem with 4.5.x clients
When removing the attachment an error occurs "Object variable not set"
Bug reported by Donna Fischer

View ($UNID) is no longer needed

%END REM


'==========================================================================================
%REM
' C L A S S "Attachment"  (frontend)
' written by Heinz Ulrich Krause, Scholler Holding, 2000     
' copy to the declaration section of action button or script library
' Thanks to Stuart Blake for bug reports 

     S A M P L E:
     ==========
Sub Click(Source As Button)
     WorkDir$ = "C:Temp"  ' The WorkDir
     Field$ = "Code"              ' RichText Field containing the attachment
     
     Dim A As New Attachment ( WorkDir$ )    ' Create a new instance of the class
     FileName$ = A.SelectAttachment ( Field$ ) ' Select an attachment
     If FileName$ = "" Then  
          Exit Sub
     Else
          Call A.DetachAndEdit( FileName$ , Field$ ) ' Detach the attachment in Field$ to        ' the workdir and open for edit in the
                               ' application associated with the file
          If  A.IsModified ( FileName$ ) Then    ' if the is any modification in the file
                               ' BEFORE removing the old attachment from the document, do your own stuff here....
               Call A.RemoveByName ( FileName$ , Field$ )  ' Delete the attachment from the doc
                              ' AFTER removing the old attachment from the document, do your own stuff here....
               Call A.Attach ( FileName$ , Field$ )                  ' and attach the file from the workdir
                              ' AFTER the new attachment is attached, do your own stuff here....
          End If
     End If
     Kill workdir$ & "" & FileName$  ' and KILL that cat
End Sub

' --------------------------------------------------------------
'  OR do it the simple ( all in one ) way
' --------------------------------------------------------------
'
Sub Click(Source As Button)
         WorkDir$ = "C:Temp1"
         Field$ = "Code"
         Dim A As New Attachment ( WorkDir$ )
         Call A.Modify ( Field$ )
End Sub

%END REM
'//==========================================================================================
' Registry Reserved Key Handles
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_CURRENT_CONFIG = &H80000005
Const HKEY_DYN_DATA = &H80000006
Const REG_SZ = 1           ' Unicode nul terminated string
Const REG_BINARY = 3  ' Free form binary
Const REG_DWORD = 4 ' 32-bit number
Const ERROR_SUCCESS = 0&
Const WINWORD = "SOFTWAREMicrosoftWindowsCurrentVersionApp PathsWinword.exe"
Const EXCEL = "SOFTWAREMicrosoftWindowsCurrentVersionApp PathsExcel.exe"
Const PROJEKT = "SOFTWAREMicrosoftWindowsCurrentVersionApp PathsWinproj.exe"
Const WIN_VERSION = "SOFTWAREMicrosoftWindows NTCurrentVersion"
Const WIN_VERSION_KEY = "ProductName"

Const INVALID_HANDLE_VALUE = -1
Const MAX_PATH = 260
Const ERROR_FILE_NO_ASSOCIATION  = 31
Const ERROR_FILE_NOT_FOUND  = 2
Const ERROR_PATH_NOT_FOUND  = 3
Const ERROR_FILE_SUCCESS = 32 
Const ERROR_BAD_FORMAT  = 11

Const cMAXLEN_BUFFER = 255
Const NORMAL_PRIORITY_CLASS = &H20&
Const INFINITE = -1&

Type RECT
	Left As Long
	Top As Long
	Right As Long
	Bottom As Long
End Type

Type POINTAPI
	x As Long
	y As Long
End Type

Type MSG
	hwnd As Long
	message As Long
	wParam As Long
	lParam As Long
	time As Long
	pt As POINTAPI
End Type

Type FILETIME
	dwLowDateTime As Long
	dwHighDateTime As Long
End Type

Type WIN32_FIND_DATA
	dwFileAttributes As Long 
	ftCreationTime As FILETIME 
	ftLastAccessTime As FILETIME 
	ftLastWriteTime As FILETIME 
	nFileSizeHigh As Long 
	nFileSizeLow As Long 
	dwReserved0 As Long 
	dwReserved1 As Long 
	cFileName As String * MAX_PATH 
	cAlternate As String * 14 
End Type

Type SYSTEMTIME
	wYear As Integer
	wMonth As Integer
	wDayOfWeek As Integer
	wDay As Integer
	wHour As Integer
	wMinute As Integer
	wSecond As Integer
	wMilliseconds As Integer
End Type

Type STARTUPINFO  
	cb As Long
	lpReserved As String
	lpDesktop As String
	lpTitle As String  
	dwX As Long 
	dwY As Long
	dwXSize As Long
	dwYSize As Long
	dwXCountChars As Long
	dwYCountChars As Long  
	dwFillAttribute As Long
	dwFlags As Long
	wShowWindow As Integer
	cbReserved2 As Integer
	lpReserved2 As Long 
	hStdInput As Long
	hStdOutput As Long
	hStdError As Long
End  Type

Type PROCESS_INFORMATION
	hProcess As Long
	hThread As Long
	dwProcessID As Long
	dwThreadID As Long
End Type

Type SHFILEOPSTRUCT
	hWnd As Long
	wFunc As Long
	pFrom As String
	pTo As String
	fFlags As Integer
	fAborted As Long
	hNameMaps As Long
	sProgress As String
End Type
'// API functions used for PopUp menue
Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos" (lpPoint As POINTAPI) As Long 
Declare Function CreatePopupMenu Lib "user32" Alias "CreatePopupMenu" () As Long
Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" (Byval hMenu As Long, 
Byval wFlags As Long, Byval wIDNewItem As Integer, Byval lpNewItem As Any) As Long< Declare Function TrackPopupMenu Lib "user32" Alias "TrackPopupMenu" (Byval hMenu As
Long, Byval wFlags As Long, Byval x As Long, Byval y As Long,
Byval nReserved As Long, Byval hwnd As Long, lprc As Rect) As Long Declare Function DestroyMenu Lib "user32" Alias "DestroyMenu" (Byval hMenu As Long) As Long Declare Function GetMessage Lib "user32" Alias "GetMessageA" (lpMsg As MSG, Byval hwnd
As Long, Byval wMsgFilterMin As Long, Byval wMsgFilterMax
As Long) As Long Declare Function GetActiveWindow Lib "user32" Alias "GetActiveWindow" () As Long '// API functions used in CLASSAttachment Declare Function FindExecutable Lib "shell32.dll" Alias
"FindExecutableA" (Byval lpFile As String, Byval lpDirectory As
String, Byval sResult As String) As Long Declare Function WaitForSingleObject Lib "kernel32" (Byval hHandle As
Long, Byval dwMilliseconds As Long) As Long Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA"
(Byval hwnd As Long, Byval lpOperation As String, Byval lpFile As
String, Byval lpParameters As String, Byval lpDirectory As String, Byval nShowCmd
As Long) As Long Declare Function CreateProcessA Lib "kernel32" (Byval lpApplicationName
As Long, Byval lpCommandLine As String, Byval lpProcessAttributes
As Long, Byval lpThreadAttributes As Long, Byval bInheritHandles As
Long, Byval dwCreationFlags As Long, _ Byval lpEnvironment As Long, Byval lpCurrentDirectory As Long,
lpStartupInfo As STARTUPINFO, lpProcessInformation As
PROCESS_INFORMATION) As Long Declare Function CloseHandle Lib "kernel32" (Byval hObject As Long) As Long Declare Function FileTimeToLocalFileTime Lib "kernel32" (lpFileTime As
FILETIME, lpLocalFileTime As FILETIME) As Long Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA"
(Byval lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA"
(Byval hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long Declare Function FindClose Lib "kernel32" (Byval hFindFile As Long) As Long Declare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime As
FILETIME, lpSystemTime As SYSTEMTIME) As Long Declare Function SystemTimeToFileTime Lib "kernel32" (lpSystemTime As
SYSTEMTIME, lpFileTime As FILETIME) As Long Declare Function RegCloseKey Lib "advapi32.dll" (Byval hKey As Long) As Long Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA"
(Byval hKey As Long, Byval lpSubKey As String, phkResult As Long) As Long Declare Function RegQueryValueEx Lib "advapi32.dll" Alias
"RegQueryValueExA" (Byval hKey As Long, Byval lpValueName As
String, Byval lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long Declare Function GetShortPathName Lib "kernel32"
Alias"GetShortPathNameA" (Byval lpszLongPath As String,Byval
lpszShortPath As String, Byval cchBuffer As Long) As Long
End of part one.
Click here for Part II
Click here for Part III
This was first published in February 2002

Dig deeper on LotusScript

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-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 ...

SearchEnterpriseLinux

SearchDataCenter

SearchExchange

SearchContentManagement

Close