I am currently working to implement a custom file browser that writes to a database instead of the file system. I have looked through the implementation that you have provided, but my requirements are a little difference (of course).
Unless I explicitly set the UploadPaths on the document manager for every path in the system, I am unable to upload any documents. I need to be able to specify the root path and allow users to work in that path without restriction once access has been granted. Here is the implementation of my provider:
Notice, for every directory item that I create, I set the permissions:
However, this is ignored. If I set the permissions via code or declaritively, it works just fine.
Thanks for any tips or advice in what I'm missing.
Unless I explicitly set the UploadPaths on the document manager for every path in the system, I am unable to upload any documents. I need to be able to specify the root path and allow users to work in that path without restriction once access has been granted. Here is the implementation of my provider:
Imports Microsoft.VisualBasic | |
Imports Telerik.Web.UI.Widgets | |
Imports SWBTS.HelpDesk.Data | |
Imports SWBTS.HelpDesk.Data.Entities | |
Namespace HelpDeskContentProvider | |
Public Class DatabaseAttachmentContentProvider | |
Inherits FileBrowserContentProvider | |
Dim _Repository As New Repository(System.Configuration.ConfigurationManager.ConnectionStrings("HelpDesk").ConnectionString) | |
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 Overrides Function CreateDirectory(ByVal path As String, ByVal name As String) As String | |
End Function | |
Public Overrides Function DeleteDirectory(ByVal path As String) As String | |
Throw New NotImplementedException("The deletion of folders is not supported. This must be done by your system database administrator.") | |
End Function | |
Public Overrides Function DeleteFile(ByVal path As String) As String | |
End Function | |
Public Overrides Function GetFile(ByVal url As String) As System.IO.Stream | |
End Function | |
Public Overrides Function GetFileName(ByVal url As String) As String | |
End Function | |
Public Overrides Function GetPath(ByVal url As String) As String | |
End Function | |
Public Overrides Function ResolveDirectory(ByVal path As String) As Telerik.Web.UI.Widgets.DirectoryItem | |
Dim directories As DirectoryItem() | |
Dim currentFolder As FileFolder = _Repository.FileFolders.GetFolder(path) | |
If DisplayMode = FileBrowserDisplayMode.Tree Then | |
directories = GetSubFolders(currentFolder.FolderID) | |
End If | |
Return New DirectoryItem(currentFolder.FolderName, String.Empty, currentFolder.FolderID, currentFolder.FolderName, PathPermissions.Read And PathPermissions.Upload, GetFilesInFolder(currentFolder.FolderID), directories) | |
End Function | |
Public Overrides Function ResolveRootDirectoryAsList(ByVal path As String) As Telerik.Web.UI.Widgets.DirectoryItem() | |
Dim folderTree As List(Of FileFolder) = _Repository.FileFolders.GetFolders() | |
Dim rootFolder As FileFolder = _Repository.FileFolders.GetFolder(path) | |
Return GetSubFolders(rootFolder.FolderID) | |
End Function | |
Public Overrides Function ResolveRootDirectoryAsTree(ByVal path As String) As Telerik.Web.UI.Widgets.DirectoryItem | |
Dim folderTree As List(Of FileFolder) = _Repository.FileFolders.GetFolders() | |
Dim rootFolder As FileFolder = (From folder In folderTree Where folder.FolderID = path).Single() | |
Dim item As DirectoryItem = CreateDirectoryItem(rootFolder) | |
Return item | |
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 | |
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 fileName As String = file.GetName() | |
Dim length As Integer = file.ContentLength | |
Dim contentType As String = file.ContentType | |
Dim extension As String = file.GetExtension() | |
Dim data(file.InputStream.Length) As Byte | |
Dim storagePath As String = StripSlashes(path) | |
file.InputStream.Read(data, 0, file.InputStream.Length) | |
Dim user As SystemUser = _Repository.Users.GetUser(My.User.Name.ToLower()) | |
Dim newFileId As Integer | |
newFileId = _Repository.Files.CreateNewFile(fileName, extension, storagePath, length, contentType, data, user).FileID | |
Return "FileHandler.ashx?fileID=" & newFileId.ToString() | |
End Function | |
Private Function GetFilesInFolder(ByVal folderID As Integer) As FileItem() | |
Dim files As List(Of FileItem) = New List(Of FileItem) | |
Dim fileList As List(Of DatabaseFileListItem) = _Repository.Files.GetFilesForFolder(folderID) | |
For Each FileItem As DatabaseFileListItem In fileList | |
Dim file As New FileItem(FileItem.FileName, FileItem.Extension, FileItem.ContentLength, String.Empty, "FileHandler.ashx?fileID=" & FileItem.FileID, String.Empty, PathPermissions.Read And PathPermissions.Delete) | |
files.Add(file) | |
Next | |
Return files.ToArray() | |
End Function | |
Private Function GetSubFolders(ByVal folderID As Integer) As DirectoryItem() | |
Dim folders As New List(Of DirectoryItem) | |
Dim subFolders = _Repository.FileFolders.GetSubFolders(folderID) | |
For Each folder In subFolders | |
Dim folderItem As DirectoryItem = CreateDirectoryItem(folder) | |
folders.Add(folderItem) | |
Next | |
Return folders.ToArray() | |
End Function | |
Private Function CreateDirectoryItem(ByVal folderItem As FileFolder) As DirectoryItem | |
Dim folderName As String = folderItem.FolderName | |
Dim folderLocation As String = folderItem.FolderID | |
Dim folderFullPath As String = folderItem.FolderID | |
Dim folderTag As String = folderItem.FolderID | |
Dim files() As FileItem = GetFilesInFolder(folderItem.FolderID) | |
Dim directories() As DirectoryItem = GetSubFolders(folderItem.FolderID) | |
Dim permission As PathPermissions = PathPermissions.Delete Or PathPermissions.Read Or PathPermissions.Upload | |
Dim Item As New DirectoryItem(folderName, folderLocation, folderFullPath, folderTag, permission, files, directories) | |
Return Item | |
End Function | |
Private Function StripSlashes(ByVal path As String) As String | |
path = path.Replace("/", "") | |
Return path | |
End Function | |
End Class | |
End Namespace | |
Notice, for every directory item that I create, I set the permissions:
Dim permission As PathPermissions = PathPermissions.Delete Or PathPermissions.Read Or PathPermissions.Upload | |
However, this is ignored. If I set the permissions via code or declaritively, it works just fine.
<DocumentManager ContentProviderTypeName="HelpDeskContentProvider.DatabaseAttachmentContentProvider, App_Code" ViewPaths="1" UploadPaths="1" DeletePaths="1"/> |
Thanks for any tips or advice in what I'm missing.