Hi there
29-06-2017 Final Version Preview..
Here is the final version of the eLibrary based on this article below.
The article below just touches on the basic stuff and not everything else included in the video above...
Before 29-06-2017
Well, I have been looking for a file manager for a while that I could use in my ABMaterial app. This file manager just provides functionality to upload and download your files, nothing fancy...
Some silly asumptions...
1. You know how to create an ABMApplication
2. You know how to create an ABMPage
3. You know how to create an ABMTable on your page
4. You know how to create an ABMUpload on your page.
Step 1: Create my table...
Step 2: Refresh the table with contents that have been uploaded. [Press Page Refresh]
To Do Perhaps...
I intend to show the icon image next to each file name. Currently this saves the icon as an image using the file extension. Perhaps a navbar to Add/Rename/Delete files and folders.
NB: The code to save icon images from files, recursive searches on directories is in the forum.
29-06-2017 Final Version Preview..
Here is the final version of the eLibrary based on this article below.
The article below just touches on the basic stuff and not everything else included in the video above...
Before 29-06-2017
Well, I have been looking for a file manager for a while that I could use in my ABMaterial app. This file manager just provides functionality to upload and download your files, nothing fancy...
Some silly asumptions...
1. You know how to create an ABMApplication
2. You know how to create an ABMPage
3. You know how to create an ABMTable on your page
4. You know how to create an ABMUpload on your page.
Step 1: Create my table...
B4X:
Dim FM As ABMTable
FM.Initialize(page, "FM", True, False, True, "tblTheme")
FM.IsBordered = True
FM.IsResponsive = True
FM.IgnoreFormattingCodes = False
FM.IsTextSelectable = True
FM.SetHeaders(Array As String("ID", "File Name", "Path", "Date Modified", "Type", "Size", "Download"))
FM.SetHeaderThemes(Array As String("bg", "bg", "bg", "bg", "bg", "bgr", "bgc"))
FM.SetHeaderHeights(Array As Int(0, 0, 0, 0, 0, 0, 48))
FM.SetColumnVisible(Array As Boolean(False, True, False, True, True, True, True))
FM.SetColumnSortable(Array As Boolean(False, True, True, True, True, True, False))
FM.SetColumnDataFields(Array As String("id", "filename", "filepath", "datemodified", "filetype", "filesize", ""))
page.Cell(5,1).AddComponent(FM)
RefreshFileManager
Step 2: Refresh the table with contents that have been uploaded. [Press Page Refresh]
B4X:
Sub RefreshFileManager
DateTime.DateFormat = "yyyy-MM-dd HH:mm"
Dim nFiles As List
nFiles.Initialize
Dim uploads As String
uploads = "uploads"
Dim filename As String
filename = ABMShared.SessionStorageRead(page, "FileManagerfilename")
Dim www As String = "www"
Dim fStructure As String = www & "/" & ABMShared.AppName & "/" & uploads
fStructure = File.Combine(fStructure,"")
ABMShared.SessionStorageSave(page, "FileManagerfilepath", File.Combine(File.DirApp, fStructure))
ABMShared.PrepareRecursiveSearch
ABMShared.ReadDir(fStructure,True)
For Each strFile As String In ABMShared.ffiles
strFile = File.Combine(File.DirApp,strFile)
Dim sfilename As String = File.GetName(strFile)
Dim sfilepath As String = File.GetFileParent(strFile)
Dim sdatemodified As String = File.LastModified("",strFile)
Dim sfileext As String = ABMShared.MvField(strFile,-1,".")
If sfileext.EqualsIgnoreCase(strFile) Then
sfileext = "unknown"
End If
Dim imgFile As String = File.Combine(File.DirApp,"www/" & ABMShared.appname & "/images/" & sfileext & ".png")
If File.Exists("",imgFile) = False Then
'try and save the image for later retrieval
Dim img As Image = ABMShared.GetFileIcon("",strFile)
ABMShared.SaveSnapShot(img, imgFile)
End If
Dim sfilesize As String = File.Size("",strFile)
sdatemodified = DateTime.Date(sdatemodified)
Dim sfiletype As String = sfileext
Dim nt As Map
nt.Initialize
nt.put("filename", sfilename)
nt.put("filepath", sfilepath)
nt.Put("fileext", sfileext)
nt.put("datemodified", sdatemodified)
nt.put("filetype", sfiletype)
nt.put("filesize", sfilesize)
nFiles.Add(nt)
Next
'Get connection from current pool if MySQL/MSSQL
Dim jSQL As SQL = ABMShared.SQLGet
'clear the file manager, this is a temporal table
ABMShared.SQLClearTable(jSQL,"FileManager","id",False)
'add new details of the files
ABMShared.SQLRecordInsertMaps(jSQL,"FileManager",nFiles)
'Close the connection to the database
ABMShared.SQLClose(jSQL)
End Sub
To Do Perhaps...
I intend to show the icon image next to each file name. Currently this saves the icon as an image using the file extension. Perhaps a navbar to Add/Rename/Delete files and folders.
NB: The code to save icon images from files, recursive searches on directories is in the forum.
Last edited: