Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Thursday, October 10, 2024 
 
View User Profile  

 User Profile - Kris Halsrud  
Kris Halsrud
(SalesLogix Business Partner)
Customer FX Corporation

fiogf49gjkf0d


Log in to send this member a message!
 


 Kris Halsrud's Contributions
Kris Halsrud has contributed 3 comments and 2 articles.
 
Select to view:    
Comment: Re: How to Save & Read Images in a SalesLogix Database
fiogf49gjkf0d
Ryan, another great article. One thing that should be touched on is how to determine the best location to create the file from the BLOB field. Because of user security and different client set ups you may not be sure a directory exists, or if it does that the user has the required rights to that directory.

SalesLogix has two built in functions for determining local paths related to SalesLogix

Application.BasicFunctions.GetAttachmentPath finds the local attachment path for the current user. This is the folder located under the Documents and Settings folder which all users should have rights to
Application.BasicFunctions.GetApplicationPath finds the directory that SalesLogix is installed to (Typically C:\Program Files\SalesLogix) This directory may not accessible to all users depending on their rights

With these two options and knowing the attachment path is better due to security concerns, this should be the choice to use here. So by writing something like this:

sFileName = Application.BasicFunctions.GetAttachmentPath & "\" & "myBLOBFile.tmp"

We can go one step further in this code by introducing the File System Object. This is a visual basic object that exposes a computers file system to scripting
Find more about the FSO at Microsoft's web site: http://msdn.microsoft.com/library/devprods/vs6/vbasic/vbenlr98/vaobjfilesystemobject.htm

To begin with you need to create an instance of the object

Dim FSO
set fso = CreateObject("Scripting.FileSystemObject")

Now one of the methods in the FSO is GetTempName, which basically generates a random temporary filename. The syntax for this is as simple as:

sFileName = fso.GetTempName

Using this we know don't even need to hard code a file name into our script. We can do something like the following to build a function. Notice my function differs from Ryan's a bit in that my function is passed a SQL statement. This allows my function to be used to extract out multiple files in different locations within the database.


Function BlobToFile(ByVal sSQL, ByVal sFieldName)
'Reads a bob DB file to temporary file for viewing purposes
Dim oCon
Dim oRS
Dim oStream
Dim fso
Dim sFileName

set fso = CreateObject("Scripting.FileSystemObject")
sFileName = Application.BasicFunctions.GetAttachmentPath & "\" & fso.GetTempName

' Create the File from a Blob
Set oCon = Application.GetNewConnection
If ChkError ("Error getting connection information:") > 0 Then
Exit Function
End If
Set oRS = CreateObject("ADODB.Recordset")
oRS.CursorLocation = adUseClient
oRS.Open sSQL, oCon
Set oStream = CreateObject("ADODB.Stream")
With oStream
.Type = adTypeBinary
.Mode = adModeReadWrite
.Open
.Write oRS.Fields(0).Value
.SaveToFile sFileName, adSaveCreateOverWrite
.Close
End With
Set oStream = Nothing
oRS.Close
Set oRS = Nothing
Set oCon = Nothing
BlobToFile = sFileName
End Function

Now to use this function we would use the following command

Sub ShowImageFromDB
Dim sFileName
sFileName = BlobToFile ("select logo from c_accountimage where accountid = '" & currentid & "'")
ImgIntro.Picture = loadpicture(sFilename)
End Sub

Now one thing we would also want to add to the code would be a command to delete the temporary file created within our function and used by the loadpicture command. To do this we can use the File System Object again and another method to delete a file, DeleteFile. Adding the following to our code accomplishes this:

Sub ShowImageFromDB
Dim fso
Dim sFileName
set fso = CreateObject("Scripting.FileSystemObject")
sFileName = BlobToFile ("select logo from c_accountimage where accountid = '" & currentid & "'")
ImgIntro.Picture = loadpicture(sFilename)
fso.deletefile sFilename
set fso = nothing
End Sub


Again, not a lot different than what Ryan initially documented but the importance of thinking about using a known valid and accessible directory makes the code a little more universal.

Author: Kris Halsrud - 5/19/2005

 
Comment: Great explanation of this
fiogf49gjkf0d
Thanks for this article Ryan, great info for being able to integrate views/ wizards together with other saleslogix screens.

Author: Kris Halsrud - 1/9/2003

 
Comment: Well done
fiogf49gjkf0d
Great demonstration of how SalesLogix 6 allows for true reusable code. This can add a lot of value for both BP and customers in the ability to rollout customizations quickly.

Author: Kris Halsrud - 11/19/2002

 


 
 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2024 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 10/10/2024 2:57:19 AM