Submitted by blake_p on Tue, 02/16/2021 - 05:14
Forums:
I create a block UI that uses an image with a path to an image file. I am trying to create a relative path to the image, store in the same folder as the .dll. I have tried value = "\bar_illustration.jpg", value = ".\bar_illustration.jpg", and value = "..\bar_illustration.jpg" with no luck.
.DLX CODE:
id="Image" mask="0" name="Image" sname="Image" source="1" type="file" value="C:\Users\Documents\bar_illustration.jpg"
Please let me know if you have any suggestions.
Thanks
re: relative path
The session has a .ExecutingJournal property that returns the name of the executing journal (I assume it also works with compiled code). On the few occasions that I've worked with DLX files, I've used the following code that allows the DLX file to run properly as long as it is in the same directory as the journal code. Perhaps a similar strategy would work for your image file.
Dim journalPath As String = theSession.ExecutingJournal
Dim journalFolder As String = System.IO.Path.GetDirectoryName(journalPath)
theDlxFileName = System.IO.Path.Combine(journalFolder, "CommaDialogTest.dlx")
theDialog = theUI.CreateDialog(theDlxFileName)
Relative Path
It is not getting the journal path since it is compiled as a .dll. If I get the .dll path I think I will be able to reference the image from the same folder. Long story short, I create a temporary dlx file to run the UI. If I store the image in this temp folder I can use the relative path. I am trying to distribute the code to other users, so by copying the original image to a temp folder and using the relative path, I should be able to use the image. But I will need to find out how to get the path of the original .dll (also where the original image is stored) so I can copy the image. Would you know how to find the directory where the .dll is run?
re: dll directory
Your programming language of choice should have methods of determining where the executing DLL file is located. A quick search on stack overflow found this for .net:
https://stackoverflow.com/questions/4764680/how-to-get-the-location-of-t...
Answer
Inside the .dlx value = "\bar_illustration.jpg" for the image file path. This creates a relative file path for the image file.
Since I am using a UI, all my code is copied to a temp folder. This is where I need to copy my image to allow for a relative path.
Dim tempSysPath As String = IO.Path.GetTempPath
'File location for bar_illustration.jpg in temp file
Dim tempFileLength As Integer = tempSysPath.Length
Dim tempJpgFileLoc As String = tempSysPath.Insert(tempFileLength, "bar_illustration.jpg")
'Check if image exists in temp folder
If System.IO.File.Exists(tempJpgFileLoc) Then
'The image exist, don't need to copy
Else
'The file does not exist and must copy image to temp location
' Gets local file location of the .dll file and creates file location for bar_illustration.jpg file
Dim assemblyfolder As String = IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase)
Dim filename As String = assemblyfolder.Remove(0, 6)
Dim filenameLength As Integer = filename.Length
Dim jpgFileLoc As String = filename.Insert(filenameLength, "\bar_illustration.jpg")
' Create a copy of the image into the temp file
My.Computer.FileSystem.CopyFile(jpgFileLoc, tempJpgFileLoc)
End If