Hi There,
Im trying to implement a custom datasource / provider for the filebrowser control.
I've looked at the related samples but am unsure which route to follow;
Any help / pointers / sample code on how to achieve this would be much appreciated!
Below is sample code that is used to retrieve files from a remote machine (Linux) and bind it to a treeview. Also include is the accosiated XML RPC wrapper class.
Usage:
Class:
Thanks,
Gordon
Im trying to implement a custom datasource / provider for the filebrowser control.
I've looked at the related samples but am unsure which route to follow;
- Subclassing the existing Telerik.Web.UI.Widgets.FileSystemContentProvider and only overriding methods that need changed.
- Implementing a new Telerik.Web.UI.Widgets.FileBrowserContentProvider
Any help / pointers / sample code on how to achieve this would be much appreciated!
Below is sample code that is used to retrieve files from a remote machine (Linux) and bind it to a treeview. Also include is the accosiated XML RPC wrapper class.
Usage:
Protected
Sub
Page_Load(
ByVal
sender
As
Object
,
ByVal
e
As
System.EventArgs)
Handles
Me
.Load
'set root path to browse on remote system
Dim
RootPath
As
String
=
"/dcinvol2/jobs"
'create root node for treeview
Dim
RootNode
As
New
TreeNode(RootPath)
'instantiate new XML RPC class
Dim
XmlRpc
As
New
Magic.XML_RPC
If
XmlRpc.IsRunning
Then
'return all files and folders
Dim
FilesAndFolders
As
New
ArrayList()
FilesAndFolders.AddRange(XmlRpc.GetFolders(RootPath,
False
,
True
, 1))
If
FilesAndFolders.Count > 0
Then
'add each file or folder to rootnode
For
Each
FileOrFolder
As
String
In
FilesAndFolders
Dim
ChildNode
As
New
TreeNode(FileOrFolder)
RootNode.ChildNodes.Add(ChildNode)
Next
'add rootnode to treeview
TreeView1.Nodes.Add(RootNode)
End
If
End
If
End
Sub
Class:
Imports
CookComputing.XmlRpc
Namespace
Magic
Public
Class
XML_RPC
Private
_iproxy
As
XmlRpcInt
Public
Sub
New
()
_iproxy =
CType
(XmlRpcProxyGen.Create(
GetType
(XmlRpcInt)), XmlRpcInt)
End
Sub
''' <summary>
''' Check if service is running.
''' </summary>
''' <returns>True if service is running, otherwise False.</returns>
Public
Function
IsRunning()
As
Boolean
Dim
strRet
As
String
Try
strRet = _iproxy.IsServerRunning()
Catch
ex
As
Exception
Return
False
End
Try
If
strRet.Length > 0
And
strRet <>
Nothing
Then
Return
True
Return
False
End
Function
''' <summary>
''' Gets all sub folders under the path specified.
''' <param name="path">Path to query.</param>
''' <param name="fullPath">Optional - return the full path</param>
''' <param name="returnFiles">Optional - return the files in a dir</param>
''' <param name="drill_to_level_x">Optional - return a depth of dirs</param>
''' </summary>
''' <returns>Array of paths.</returns>
Function
GetFolders(
ByVal
path
As
String
,
Optional
ByVal
fullPath
As
Boolean
=
True
,
Optional
ByVal
returnFiles
As
Boolean
=
False
,
Optional
ByVal
drill_to_level_x
As
Integer
= 0)
As
Array
Dim
al
As
New
ArrayList
Try
Dim
a
As
Array =
Nothing
a = _iproxy.GetFolders(path, fullPath, returnFiles, drill_to_level_x)
For
Each
s
As
String
In
a
'Perform clean up
If
s =
"."
Then
Continue
For
If
s.StartsWith(
"."
)
Then
s = s.TrimStart(
"."
)
If
s.StartsWith(
"/"
)
Then
s = s.TrimStart(
"/"
)
al.Add(s)
Next
Catch
ex
As
Exception
Return
al.ToArray
End
Try
Return
al.ToArray
End
Function
''' <summary>
''' Looks for file specified and returns file in binary format.
''' </summary>
''' <param name="filename">The full path to file, including filename.</param>
''' <returns>Array in bytecode format.</returns>
Function
GetBinaryFile(
ByVal
filename
As
String
)
As
Array
Dim
a
As
Array =
Nothing
Try
a = _iproxy.GetBinaryFile(filename)
Catch
ex
As
Exception
Return
a
End
Try
Return
a
End
Function
''' <summary>
''' Checks if given path exists.
''' </summary>
''' <param name="path">The full path to folder/file.</param>
''' <param name="folder">Check folder or file exists.</param>
''' <returns>True if path exists, False otherwise.</returns>
Function
PathExists(
ByVal
path
As
String
,
Optional
ByVal
folder
As
Boolean
=
True
)
As
Boolean
Try
Return
_iproxy.PathExists(path, folder)
Catch
ex
As
Exception
Return
False
End
Try
End
Function
''' <summary>
''' Returns number of files in given path, currently this descends into sub folders.
''' </summary>
''' <param name="path">The full path to folder.</param>
''' <returns>Number of files in the path.</returns>
Function
GetNumberOfFiles(
ByVal
path
As
String
)
As
Integer
Dim
i
As
Integer
= 0
Try
i =
CInt
(_iproxy.GetNumberOfFiles(path))
Catch
ex
As
Exception
Return
i
End
Try
Return
i
End
Function
''' <summary>
''' Returns number of kilobytes in given path.
''' </summary>
''' <param name="path">The full path to folder.</param>
''' <returns>Number of kilobytes in the path.</returns>
Function
GetByteSize(
ByVal
path
As
String
)
As
Integer
Dim
i
As
String
= 0
Try
i =
CInt
(_iproxy.GetByteSize(path))
Catch
ex
As
Exception
Return
i
End
Try
Return
i
End
Function
End
Class
End
Namespace
Thanks,
Gordon