| Public Class ContentEditorProvider |
| Inherits FileBrowserContentProvider |
| Private _LoadDirectory As String |
| Private _ImgDirectory As String |
| Private _DocumentsDirectory As String |
| Private _SecureDocumentsDirectory As String |
| Private _FullPermissions As PathPermissions = PathPermissions.Read Or PathPermissions.Delete Or PathPermissions.Upload |
| Public Sub New(ByVal context As HttpContext, ByVal searchPatterns As String(), ByVal viewPaths As String(), ByVal uploadPaths As String(), ByVal deletePaths As String(), ByVal selectedUrl As String, ByVal selectedItemTag As String) |
| MyBase.New(context, searchPatterns, viewPaths, uploadPaths, deletePaths, selectedUrl, selectedItemTag) |
| End Sub |
| Public Overloads Overrides ReadOnly Property CanCreateDirectory() As Boolean |
| Get |
| Return True |
| End Get |
| End Property |
| Public Overrides Function CreateDirectory(ByVal path As String, ByVal name As String) As String |
| Dim RealPath As String = IO.FileSystem.ResolveDirectory(path) |
| Directory.CreateDirectory(RealPath & "\" & name) |
| Return path & name |
| End Function |
| Public Overrides Function DeleteDirectory(ByVal path As String) As String |
| DeleteDirectory = IO.FileSystem.ResolveDirectory(path) |
| If Directory.Exists(DeleteDirectory) Then Directory.Delete(DeleteDirectory, True) |
| DeleteDirectory = String.Empty |
| Return DeleteDirectory |
| End Function |
| Public Overrides Function DeleteFile(ByVal path As String) As String |
| DeleteFile = IO.FileSystem.ResolveDirectory(path) |
| If File.Exists(DeleteFile) Then File.Delete(DeleteFile) |
| DeleteFile = String.Empty |
| Return DeleteFile |
| End Function |
| Public Overrides Function GetFile(ByVal url As String) As System.IO.Stream |
| Dim RealPath As String = IO.FileSystem.ResolveURL(url) |
| If System.IO.File.Exists(RealPath) = True Then |
| Dim File As Byte() = System.IO.File.ReadAllBytes(RealPath) |
| GetFile = New MemoryStream(File) |
| Else |
| GetFile = Nothing |
| End If |
| Return GetFile |
| End Function |
| Private Function GetName(ByVal path As String) As String |
| GetName = IIf(path = Nothing, String.Empty, path.Substring(path.LastIndexOf("\"c) + 1)) |
| Return GetName |
| End Function |
| Public Overrides Function GetFileName(ByVal url As String) As String |
| GetFileName = IIf(url = Nothing, String.Empty, url.Substring(url.LastIndexOf("/"c) + 1)) |
| Return GetFileName |
| End Function |
| Public Overrides Function GetPath(ByVal url As String) As String |
| GetPath = IO.FileSystem.ResolveURL(url) |
| Return GetPath |
| End Function |
| Public Function LoadFiles(ByVal Dir As System.IO.DirectoryInfo) As FileItem() |
| Dim xFiles As New List(Of FileItem) |
| For Each Fil As FileInfo In Dir.GetFiles() |
| Dim RealPath As String = Fil.FullName |
| Dim VirtualPath As String = IO.FileSystem.TranslateDirectory(RealPath) |
| Dim VirtualURL As String = IO.FileSystem.TranslateURL(RealPath) |
| xFiles.Add(New FileItem(Fil.Name, Fil.Extension, Fil.Length, VirtualPath, VirtualURL, VirtualPath, _FullPermissions)) |
| Next |
| Return xFiles.ToArray |
| End Function |
| Public Function LoadDirectories(ByVal Dir As System.IO.DirectoryInfo) As DirectoryItem() |
| Dim xDir As New List(Of DirectoryItem) |
| For Each SubDir As DirectoryInfo In Dir.GetDirectories() |
| Dim RealPath As String = SubDir.FullName |
| Dim VirtualPath As String = IO.FileSystem.TranslateDirectory(RealPath) |
| xDir.Add(New DirectoryItem(SubDir.Name, VirtualPath, VirtualPath, VirtualPath, _FullPermissions, LoadFiles(SubDir), LoadDirectories(SubDir))) |
| Next |
| Return xDir.ToArray |
| End Function |
| Public Overrides Function ResolveDirectory(ByVal path As String) As Telerik.Web.UI.Widgets.DirectoryItem |
| Dim RealPath As String = IO.FileSystem.ResolveDirectory(path) |
| Dim VirtualPath As String = IO.FileSystem.TranslateDirectory(RealPath) |
| Dim DirInfo As New DirectoryInfo(RealPath) |
| ResolveDirectory = New DirectoryItem(DirInfo.Name, VirtualPath, VirtualPath, IO.FileSystem.TranslateURL(VirtualPath), _FullPermissions, LoadFiles(DirInfo), LoadDirectories(DirInfo)) |
| Return ResolveDirectory |
| End Function |
| Public Overrides Function ResolveRootDirectoryAsList(ByVal path As String) As Telerik.Web.UI.Widgets.DirectoryItem() |
| If path.StartsWith("/") = True Then path = IO.FileSystem.ResolveDirectory(path) |
| Dim RealPath As String = IO.FileSystem.ProcessDirectory(path) |
| Dim DirInfo As New DirectoryInfo(RealPath) |
| ResolveRootDirectoryAsList = LoadDirectories(DirInfo) |
| Return ResolveRootDirectoryAsList |
| End Function |
| Public Overrides Function ResolveRootDirectoryAsTree(ByVal path As String) As Telerik.Web.UI.Widgets.DirectoryItem |
| If path.StartsWith("/") = True Then path = IO.FileSystem.ResolveDirectory(path) |
| Dim RealPath As String = IO.FileSystem.ProcessDirectory(path) |
| Dim VirtualPath As String = IO.FileSystem.TranslateDirectory(RealPath) |
| Dim DirInfo As New DirectoryInfo(RealPath) |
| 'HttpContext.Current.Response.Write(path & " - " & RealPath & " - " & VirtualPath) |
| 'HttpContext.Current.Response.End() |
| ResolveRootDirectoryAsTree = New DirectoryItem(DirInfo.Name, VirtualPath, VirtualPath, VirtualPath, _FullPermissions, LoadFiles(DirInfo), LoadDirectories(DirInfo)) |
| Return ResolveRootDirectoryAsTree |
| End Function |
| Public Overrides Function StoreBitmap(ByVal bitmap As System.Drawing.Bitmap, ByVal url As String, ByVal format As System.Drawing.Imaging.ImageFormat) As String |
| Dim RealPath As String = IO.FileSystem.ResolveURL(url) |
| Dim newItemPath As String = IO.FileSystem.ResolveURL(url) |
| Dim name As String = GetName(newItemPath) |
| Dim _path As String = GetPath(newItemPath) |
| Dim tempFilePath As String = Path.GetTempFileName() |
| bitmap.Save(tempFilePath) |
| Dim content As Byte() |
| Using inputStream As FileStream = File.OpenRead(tempFilePath) |
| Dim size As Long = inputStream.Length |
| content = New Byte(size) {} |
| inputStream.Read(content, 0, CType(size, Integer)) |
| End Using |
| If File.Exists(tempFilePath) Then |
| File.Delete(tempFilePath) |
| End If |
| File.WriteAllBytes(RealPath, content) |
| Return url |
| End Function |
| Public Overloads Overrides Function StoreFile(ByVal file As Telerik.Web.UI.UploadedFile, ByVal path As String, ByVal name As String, ByVal ParamArray arguments() As String) As String |
| Dim FullName As String = IO.FileSystem.ResolveDirectory(path) & "\" & name |
| file.SaveAs(FullName) |
| Return path & name |
| End Function |
| End Class |