This is a migrated thread and some comments may be shown as answers.
CustomContentProvider Doesn't work after Q1 SP1 Update
10 Answers 249 Views
This is a migrated thread and some comments may be shown as answers.
Dave
Top achievements
Rank 1
Dave asked on 21 Apr 2009, 03:27 AM
Ok everyone, I am sort of at your mercy here... I have spent several hours debugging trying to figure out why the manager aren't working and it seems to all point to that the new dialogs are expecting return strings in different formats.  Here is the background on the application environment.

The admin application that contains the editor is in a different directory / application than the public website where the content is rendered. The images and flash folders are sub folders of the public site and there is a third securedocuments folder that sits outside of the publicwwwroot.  These files are streamed using a httphandler.

Directory Structure:
    - Drive:\SolutionFolder
                                        -\adminwwwroot
                                        -\publicwwwroot
                                        -\publicwwwroot\Images
                                        -\publicwwwroot\Flash
                                        -\publicwwwroot\Documents

                                                                -\publicwwwroot
                                        -\securedocuments

URL Structure:
    - http://www.publicdomain.com/
                                                    /Images
                                                    /Flash
                                                    /Documents
                                                    /SecureDocuments.ashx?path=file.ext
    - http://adminsubdomain.publicdomain.com/
                                                                         /RadEditor.aspx?updatepage=1

I have worked with the code and got the files to list and new directories to create and delete.  But upload / rename files are still not working... I haven't tried saving an image using the image editor yet.

I will provide you the customcontentprovider code and the filesystem code that supplies the directory and url structure as seen above.  Here are my exact issues and what solutions I would like to see:
    1.) Rename File - Call Stack Shows RenameFile function being called in the RadFileExplorer class in the Telerik.web.ui.dll
             What changed? Why? Fixes?
    2.) Upload File - This is the highest priority for me to get fixed.  The StoreFile function doesn't even fire anymore.  I can't get the break point to work anymore after the upgrade.....

With all of the bugs in this new RadFileExplorer I would prefer to use the old managers if possible... Not sure how to do that... any help would be appreciated.  Thanks in advance!

New FileHandler Code (Partially Working):
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 StringByVal 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 StringByVal name As StringAs 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 StringAs 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 StringAs 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 StringAs 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 StringAs String 
                GetName = IIf(path = NothingString.Empty, path.Substring(path.LastIndexOf("\"c) + 1)) 
                Return GetName 
            End Function 
            Public Overrides Function GetFileName(ByVal url As StringAs String 
                GetFileName = IIf(url = NothingString.Empty, url.Substring(url.LastIndexOf("/"c) + 1)) 
                Return GetFileName 
            End Function 
            Public Overrides Function GetPath(ByVal url As StringAs 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 StringAs 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 StringAs 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 StringAs 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 StringByVal 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 StringByVal name As StringByVal ParamArray arguments() As StringAs String 
                Dim FullName As String = IO.FileSystem.ResolveDirectory(path) & "\" & name 
                file.SaveAs(FullName) 
                Return path & name 
            End Function 
        End Class 

Original FileHandlerCode (Only the changed functions) (Works with Q3 2008)

Public Overrides Function CreateDirectory(ByVal path As StringByVal name As StringAs String 
                Dim RealPath As String = IO.FileSystem.ResolveDirectory(path) 
                Directory.CreateDirectory(RealPath & "\" & name) 
                Return path & "/" & name 
            End Function 
Public Overrides Function ResolveRootDirectoryAsList(ByVal path As StringAs Telerik.Web.UI.Widgets.DirectoryItem() 
                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 StringAs Telerik.Web.UI.Widgets.DirectoryItem 
                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 

Here is the IO.FileSystem Class

Public Class FileSystem 
        Public Shared siteDomain As String = Configuration.Environment.SiteDomain 
        Public Shared siteRoot As String = Configuration.Environment.SiteRoot 
        Public Shared siteSecureDocuments As String = Configuration.Environment.SiteSecureDocuments 
        Public Shared dirRoot As String = Configuration.FileSystem.RootDirectory 
        Public Shared rgxDirRoot As String = Replace(dirRoot, "\""\\"
        Public Shared dirDomain As String = Configuration.FileSystem.PublicSiteDirectory 
        Public Shared rgxDirDomain As String = Replace(dirDomain, "\""\\"
        Public Shared dirSecureDocuments As String = Configuration.FileSystem.SecureDocumentsDirectory 
        Public Shared rgxDirSecureDocuments As String = Replace(dirSecureDocuments, "\""\\"
        Public Shared vfsSecureDocuments As String = Replace(siteSecureDocuments, "\""/"
        Public Shared Function QueryDirectory(ByVal path As StringOptional ByVal search As String = "*.*"Optional ByVal options As SearchOption = SearchOption.TopDirectoryOnly) As ListItemCollection 
            QueryDirectory = New ListItemCollection 
            Dim xDir As New DirectoryInfo(path) 
            path = Replace(path, "\""\\"
            For Each xFile As FileInfo In xDir.GetFiles(search, options) 
                QueryDirectory.Add(New ListItem(Replace(Regex.Replace(xFile.FullName, path, "", RegexOptions.IgnoreCase), "\""/"))) 
            Next 
            Return QueryDirectory 
        End Function 
        Public Shared Function ProcessDirectory(ByVal path As StringAs String 
            ProcessDirectory = path 
            Dim _TokenPattern As String = "\[\[(?<ConfigVar>(.)*?)\]\]" 
            Dim _RM As Match = Regex.Match(path, _TokenPattern) 
            Dim HasMatch As Boolean = False 
            HasMatch = _RM.Success 
            While HasMatch = True 
                Dim _Token As String = _RM.Groups("ConfigVar").Value 
                'System.Web.HttpContext.Current.Response.Write(_Token & "<br />") 
                _Token = Configuration.AppSettings.GetSetting(_Token) 
 
                'System.Web.HttpContext.Current.Response.Write(_Token) 
                'System.Web.HttpContext.Current.Response.End() 
                ProcessDirectory = Replace(ProcessDirectory, _RM.Value, _Token) 
                _RM = _RM.NextMatch() 
                HasMatch = _RM.Success 
            End While 
            ProcessDirectory = Replace(ProcessDirectory, "/""\"
            Return ProcessDirectory 
        End Function 
        Public Shared Function ResolveDirectory(ByVal path As StringAs String 
            ResolveDirectory = path 
            If InStrRev(ResolveDirectory, ".") > InStrRev(ResolveDirectory, "/"Then 
                ResolveDirectory = Left(ResolveDirectory, InStrRev(ResolveDirectory, "/")) 
            End If 
            If ResolveDirectory.StartsWith(dirRoot) = False Then 
                If ResolveDirectory.StartsWith(vfsSecureDocuments) = True Then 
                    ResolveDirectory = Regex.Replace(ResolveDirectory, vfsSecureDocuments, dirRoot & dirSecureDocuments, RegexOptions.IgnoreCase) 
                    ResolveDirectory = Replace(ResolveDirectory, "/""\"
                Else 
                    ResolveDirectory = dirRoot & dirDomain & ResolveDirectory 
                    ResolveDirectory = Replace(ResolveDirectory, "/""\"
                End If 
            End If 
            Return ResolveDirectory 
        End Function 
        Public Shared Function ResolveURL(ByVal Url As StringAs String 
            If siteRoot.Length > 0 Then siteRoot = Left(siteRoot, siteRoot.Length - 1) 
            ResolveURL = Url 
            ResolveURL = Regex.Replace(ResolveURL, siteDomain & siteRoot, String.Empty, RegexOptions.IgnoreCase) 
            ResolveURL = ResolveDirectory(ResolveURL) 
            Return ResolveURL 
        End Function 
        Public Shared Function TranslateURL(ByVal path As StringAs String 
            Dim strSiteRoot As String = siteRoot 
            If strSiteRoot.Length > 0 Then siteRoot = Left(strSiteRoot, siteRoot.Length - 1) 
            path = Regex.Replace(path, rgxDirRoot, "", RegexOptions.IgnoreCase) 
            path = Regex.Replace(path, rgxDirSecureDocuments, siteDomain & siteSecureDocuments, RegexOptions.IgnoreCase) 
            path = Regex.Replace(path, rgxDirDomain, siteDomain & strSiteRoot, RegexOptions.IgnoreCase) 
            path = Replace(path, "\""/"
            TranslateURL = path 
            Return TranslateURL 
        End Function 
        Public Shared Function TranslateDirectory(ByVal path As StringAs String 
            path = Regex.Replace(path, rgxDirRoot, "", RegexOptions.IgnoreCase) 
            path = Regex.Replace(path, rgxDirDomain, "", RegexOptions.IgnoreCase) 
            path = Regex.Replace(path, rgxDirSecureDocuments, vfsSecureDocuments, RegexOptions.IgnoreCase) 
            path = Replace(path, "\""/"
            TranslateDirectory = path 
            Return TranslateDirectory 
        End Function 
    End Class 




10 Answers, 1 is accepted

Sort by
0
Lini
Telerik team
answered on 27 Apr 2009, 11:00 AM
Hello David,

The new features of the RadFileExplorer control (moving and renaming files/folders) required an update to the default content provider. There are two new functions you need to override - MoveFile and MoveDirectory.
These two functions are called when moving or renaming items in the FileExplorer. They take two parameters - old and new name for the item. If the old and new name are in the same folder, the item is only renamed. If they are in different folders, then the item is being moved. When you implement these methods in your content provider, they will be called by the respective functions of the RadFileExplorer.

The only difference in the upload functionality is an added security check to make sure that you are writing to a folder, which is part of the UploadPaths collection. For example, if the file you wish to upload will have a virtual path "/Images/new/image.gif" then either "/Images/new/" or "/Images/" or "/" should be in the UploadPaths collection. If they are not, you will see an alert message "Cannot write to target folder" when you try to upload the file.

I hope that these two hints will help you get your custom provider to work again. If you still have problems, please send us a small test project with your provider code and a page using the editor so we can see the problems and fix your code accordingly. I tried to use the code you sent here but it seems that it is missing some parts( Configuration.Environment object, Configuration.FileSystem object, and some application settings).
 

Sincerely yours,
Lini
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Dave
Top achievements
Rank 1
answered on 07 May 2009, 05:02 PM
ok the file rename / move files, directories seem to be working but i am still having an awful time uploading files... can i overload this check to just return true every time?    I have tried everything...

  I know the problem is:
   
Telerik.Web.UI.RadFileExplorer.CheckWritePermissions(String) : Boolean
Telerik.Web.UI.RadFileExplorer.ProcessUploadedFiles() : Void

Here is the additional code requested....


Namespace Configuration 
    Public Class FileSystem 
        Public Shared ReadOnly Property DocumentsDirectory() 
            Get 
                Return AppSettings.GetSetting("FileSystem.Sub.Documents"
            End Get 
        End Property 
        Public Shared ReadOnly Property FlashDirectory() 
            Get 
                Return AppSettings.GetSetting("FileSystem.Sub.Flash"
            End Get 
        End Property 
        Public Shared ReadOnly Property ImagesDirectory() 
            Get 
                Return AppSettings.GetSetting("FileSystem.Sub.Images"
            End Get 
        End Property 
        Public Shared ReadOnly Property PublicSiteDirectory() 
            Get 
                Return AppSettings.GetSetting("FileSystem.Sub.PublicSite"
            End Get 
        End Property 
        Public Shared ReadOnly Property RootDirectory() 
            Get 
                Return AppSettings.GetSetting("FileSystem.Root"
            End Get 
        End Property 
        Public Shared ReadOnly Property SecureDocumentsDirectory() 
            Get 
                Return AppSettings.GetSetting("FileSystem.Sub.SecureDocuments"
            End Get 
        End Property 
    End Class 
    Public Class Environment 
        Public Shared ReadOnly Property Browser() As String 
            Get 
                Return Current.Request.Browser.Browser 
            End Get 
        End Property 
        Public Shared ReadOnly Property BrowserVersion() As String 
            Get 
                Return Current.Request.Browser.Version 
            End Get 
        End Property 
        Public Shared ReadOnly Property Domain() As String 
            Get 
                If Current.Request.IsSecureConnection = True Then 
                    Return AppSettings.GetSetting("Environment.SiteSecureDomain"
                Else 
                    Return AppSettings.GetSetting("Environment.SiteDomain"
                End If 
            End Get 
        End Property 
        Public Shared ReadOnly Property HomePage() As String 
            Get 
                Return Configuration.AppSettings.GetSetting("Environment.HomePage"
            End Get 
        End Property 
        Public Shared ReadOnly Property HttpUserAgent() As String 
            Get 
                Return Current.Request.ServerVariables("HTTP_USER_AGENT"
            End Get 
        End Property 
        Public Shared ReadOnly Property HttpHost() As String 
            Get 
                Return Current.Request.ServerVariables("HTTP_HOST"
            End Get 
        End Property 
        Public Shared ReadOnly Property HttpReferer() As String 
            Get 
                If Current.Request.ServerVariables("HTTP_REFERER") IsNot Nothing Then Return Current.Request.ServerVariables("HTTP_REFERER"Else Return "" 
            End Get 
        End Property 
        Public Shared ReadOnly Property LocalHost() As String 
            Get 
                Return Current.Request.ServerVariables("LOCAL_ADDR"
            End Get 
        End Property 
        Public Shared ReadOnly Property RawUrl() As String 
            Get 
                Return Current.Request.RawUrl 
            End Get 
        End Property 
        Public Shared ReadOnly Property RegexModule() As String 
            Get 
                Return "(\<div(.)*class=\""SI-DONOTEDIT\""(.)*\>)(\[\[(?<moduleType>classmodule|webmodule):(?<moduleResource>(.)*)\]\])(\</div>)" 
            End Get 
        End Property 
        Public Shared ReadOnly Property RegexSiteMapLink() As String 
            Get 
                Return "\" & """" & "SiteMap:(?<SiteMapID>(\d)*?)" & "\" & """" 
            End Get 
        End Property 
        Public Shared ReadOnly Property SiteRoot() As String 
            Get 
                Return AppSettings.GetSetting("Environment.SiteRoot"
            End Get 
        End Property 
        Public Shared ReadOnly Property SiteDomain() As String 
            Get 
                Return AppSettings.GetSetting("Environment.SiteDomain"
            End Get 
        End Property 
        Public Shared ReadOnly Property SiteSecureDomain() As String 
            Get 
                Return AppSettings.GetSetting("Environment.SiteSecureDomain"
            End Get 
        End Property 
        Public Shared ReadOnly Property SiteSecureDocuments() 
            Get 
                Return AppSettings.GetSetting("Environment.SiteSecureDocuments"
            End Get 
        End Property 
        Public Shared ReadOnly Property SiteSecurePages() As String 
            Get 
                Return AppSettings.GetSetting("Environment.SiteSecurePages"
            End Get 
        End Property 
        Public Shared Function ConfigFormat(ByVal configSetting As StringAs String 
            ConfigFormat = configSetting 
            If IsDevServer() = True Then ConfigFormat = "Dev." & configSetting 
            If IsDebugServer() = True Then ConfigFormat = "Debug." & configSetting 
            Return ConfigFormat 
        End Function 
        Public Shared Function IsDebugServer() As Boolean 
            Dim DebugServerHost As String = ConfigurationManager.AppSettings("Global.DebugServerHost"
            If DebugServerHost = LocalHost Then IsDebugServer = True Else IsDebugServer = False 
            Return IsDebugServer 
        End Function 
        Public Shared Function IsDevServer() As Boolean 
            Dim DevServerHost As String = ConfigurationManager.AppSettings("Global.DevServerHost"
            If DevServerHost = LocalHost Then IsDevServer = True Else IsDevServer = False 
            Return IsDevServer 
        End Function 
        Public Shared Function IsInternetExplorer() As Boolean 
            If UCase(Browser) = "IE" Then IsInternetExplorer = True Else IsInternetExplorer = False 
            Return IsInternetExplorer 
        End Function 
        Public Shared Function IsIE6() As Boolean 
            If IsInternetExplorer() = True And Left(BrowserVersion, 1) = "6" Then IsIE6 = True Else IsIE6 = False 
            Return IsIE6 
        End Function 
        Public Shared Function IsLiveServer() As Boolean 
            IsLiveServer = True 
            If IsDebugServer() = True Then IsLiveServer = False Else If IsDevServer() = True Then IsLiveServer = False 
            Return IsLiveServer 
        End Function 
    End Class 
    Public Class AppSettings 
        Public Shared Function GetSetting(ByVal SettingName As StringAs String 
            Return ConfigurationManager.AppSettings(Environment.ConfigFormat(SettingName)) 
        End Function 
    End Class 
    Public Class ConnectionStrings 
        Public Shared Function GetConnectionString(ByVal ConnectionName As StringAs String 
            Return ConfigurationManager.ConnectionStrings(Environment.ConfigFormat(ConnectionName)).ConnectionString 
        End Function 
        Public Shared Function GetIndexServiceString(ByVal CatalogName As StringAs String 
            Return "Provider=""MSIDXS"";Data Source=" & """" & CatalogName & """" & ";" 
        End Function 
    End Class 
End Namespace 
 


<appSettings> 
    <!-- GLOBAL SETTINGS --> 
    <add key="Global.DebugServerHost" value="127.0.0.1"/> 
    <add key="Global.DevServerHost" value="192.168.0.10"/> 
    <add key="Telerik.WebControls.SkinPath" value="~/Style/Skins/"/> 
    <!-- GLOBAL SETTINGS --> 
 
    <!-- DEVELOPMENT SETTINGS --> 
    <add key="Dev.Configuration.AdminOrgs" value="1993" /> 
    <add key="Dev.Configuration.IndexCatalog" value="CATALOGNAME" /> 
    <add key="Dev.Editor.CssFile" value="../style/editor.css"/> 
    <add key="Dev.Editor.DocumentManager.Paths" value="[[FileSystem.Root]][[FileSystem.Sub.Documents]],[[FileSystem.Root]][[FileSystem.Sub.SecureDocuments]]"/> 
    <add key="Dev.Editor.FlashManager.Paths" value="[[FileSystem.Root]][[FileSystem.Sub.Flash]]"/> 
    <add key="Dev.Editor.ImageManager.Paths" value="[[FileSystem.Root]][[FileSystem.Sub.Images]]"/> 
    <add key="Dev.Editor.Skin" value="Default" /> 
    <add key="Dev.Editor.ToolsFile" value="htmleditor.config" /> 
    <add key="Dev.Environment.HomePage" value="/Home"/> 
    <add key="Dev.Environment.SiteDocuments" value="/Documents"/> 
    <add key="Dev.Environment.SiteDomain" value="http://dev.domain.com"/> 
    <add key="Dev.Environment.SiteRoot" value="/"/> 
    <add key="Dev.Environment.SiteSecureDomain" value="http://dev.domain.com"/> 
    <add key="Dev.Environment.SiteSecurePages" value="/Authenticate"/> 
    <add key="Dev.Environment.SiteSecureDocuments" value="/Secure/Documents"/> 
    <add key="Dev.Environment.SplashPage" value="/home"/> 
    <add key="Dev.Error.404" value="/Error/404-Not-Found.aspx"/> 
    <add key="Dev.FileSystem.Root" value="F:\data\Clients\Client\Web" /> 
    <add key="Dev.FileSystem.Sub.AwardsSubmissions" value="\publicwwwroot\Awards\Submissions"/> 
    <add key="Dev.FileSystem.Sub.BestPracticeCalls" value="\publicwwwroot\Media-Center\BestPractice" /> 
    <add key="Dev.FileSystem.Sub.Documents" value="\publicwwwroot\Documents" /> 
    <add key="Dev.FileSystem.Sub.EventDatabase" value="\SecureDocuments\Event-Database" /> 
    <add key="Dev.FileSystem.Sub.Flash" value="\publicwwwroot\Flash" /> 
    <add key="Dev.FileSystem.Sub.Images" value="\publicwwwroot\Images" /> 
    <add key="Dev.FileSystem.Sub.PublicSite" value="\publicwwwroot" /> 
    <add key="Dev.FileSystem.Sub.SecureDocuments" value="\SecureDocuments" /> 
    <add key="Dev.Net.Mail.SMTPServer" value="192.168.0.10" /> 
    <add key="Dev.Net.Mail.SMTPPort" value="25" /> 
    <add key="Dev.Net.Mail.From" value="email@domain.com" /> 
    <add key="Dev.Net.Mail.ContactUs" value="email@domain.com" /> 
    <add key="Dev.Net.Mail.ErrorReport" value="email@domain.com" /> 
    <add key="Dev.Net.Mail.ErrorReportCC" value="email@domain.com" /> 
    <add key="Dev.SiteMap.Skin" value="Default" /> 
    <add key="Dev.Web.HttpRuntime.QueryStringKey" value="/Page-Data/" /> 
    <!-- DEVELOPMENT SETTINGS --> 
 
</appSettings> 



0
Brad
Top achievements
Rank 2
answered on 08 May 2009, 01:15 AM
Hi,

I'm having a similar problem with the file upload piece.  I downloaded the source code to the RadFileExplorer, and I think I see what's causing my problem, and I'm hoping somebody can either tell me if (1) it's a bug, or (2) it's right, and I just don't understand how it's supposed to work. 

The problem is that when I try to upload a file, it always returns with a "Cannot Write to Folder" message.  I've isolated the problem down to the function CheckWritePermissions
private bool CheckWritePermissions(string uploadFolder)  
        {  
            //Init content provider to update upload paths if needed!  
            InitContentProvider(uploadFolder);  
 
            //compare the upload folder to all paths in the UploadPaths collection and check if it is a child or one of them.  
            //Paths are case-sensitive!  
            foreach (string uploadPath in Configuration.UploadPaths)  
            {  
                if (!String.IsNullOrEmpty(uploadPath) && uploadFolder.StartsWith(uploadPath))  
                {  
                    if (uploadFolder.Length > uploadPath.Length && uploadFolder[uploadPath.Length] == pathSeparator)  
                    {  
                        return true;  
                    }  
                    else if (uploadPath.Length == uploadFolder.Length)  
                    {  
                        return true;  
                    }  
                }  
            }  
            return false;  
        } 

My specific problem occurs on line 12.  In my case, uploadFolder = "/webdocs/", and uploadPath = "/".  This gets me to line 12.  The first part of the if condition evaluates as True, so we're good there, but the second part does not. 
uploadFolder[uploadPath.Length]
"/webdocs/" [1] == "w" 
"w" != "/".

I'm wondering if the second part of the if condition on line 12 should be
uploadFolder[uploadPath.Length-1] == pathSeparator.

Or, am I way off base here?

Thanks for your help and guidance.

 --Brad
0
Accepted
Lini
Telerik team
answered on 08 May 2009, 11:10 AM
Hello Brad,

Here is the current state of the CheckWritePermissions method. I think that the problem you experienced will not happen with this code:

private bool CheckWritePermissions(string uploadFolder) 
    //Init content provider to update upload paths if needed! 
    InitContentProvider(uploadFolder); 
    //add a ending slash to the upload folder 
    uploadFolder = uploadFolder.TrimEnd(new char[] { pathSeparator }) + pathSeparator; 
 
    //compare the upload folder to all paths in the UploadPaths collection and check if it is a child or one of them. 
    //Paths are case-sensitive! 
    foreach (string uploadPath in Configuration.UploadPaths) 
    { 
        if (!String.IsNullOrEmpty(uploadPath) && uploadFolder.StartsWith(uploadPath)) 
        { 
            //remove trailing slash from upload path 
            string trimmedUploadPath = uploadPath.TrimEnd(new char[] { pathSeparator }); 
            if (trimmedUploadPath.Length == 0) 
            { 
                //empty upload path - give permissions everywhere 
                return true
            } 
            if (uploadFolder.Length > trimmedUploadPath.Length && uploadFolder[trimmedUploadPath.Length] == pathSeparator) 
            { 
                return true
            } 
        } 
    } 
    return false

We make sure the upload folder ends with a slash and that the paths that are checked do not. This way uploadFolder[uploadPath.Length] should always be a slash and the check will pass.

Best wishes,
Lini
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Dave
Top achievements
Rank 1
answered on 08 May 2009, 02:13 PM
the latest internal build seemed to fix the issue with uploading files only if you use "/" for your upload path... IE it doesn't accept the full path anymore, but that is fine.... the storebitmap functions still doesn't seem to be firing as it appears to be getting hung up on the same problem (can't write to target folder)...
0
Dave
Top achievements
Rank 1
answered on 13 May 2009, 04:27 PM
the internal build (5/13/09) fixed the last remaining issues.  Anyone having problems with a custom content provider moving from Q3 to Q1 should try using that build.  Also send the telerik team a support ticket if necessary.... they were extremely helpful! 
0
Marc Messer
Top achievements
Rank 2
answered on 08 Feb 2010, 08:19 PM
While uploading was resolved on this a while back.  It seems that both renaming and deleting no longer works.  I tried changing the deletepath = "/" like i did with the upload path but still no luck.  please reference the source code from dave.
0
Fiko
Telerik team
answered on 11 Feb 2010, 12:39 PM
Hello Marc,

In Q3 2009 SP1 version of the controls and later we introduced a new method to the FileBrowserContentProvider named CheckDeletePermissions. Could you please override it in your content provider and implement a logic in it that will calculate the delete permissions of the file/folder? I ask you this because the CheckDeletePermissions method is called when a folder is moved (the Rename and Move are the same operations). In case, however, the problem still exists, could you please open a new support ticket and send me a project that reproduces the problem? I will debug it on my side and do my best to provide a working solution as soon as possible.


I hope this helps.

Regards,
Fiko
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Marc Messer
Top achievements
Rank 2
answered on 11 Feb 2010, 05:21 PM
that seemed to fix everything but the rename.  I can drag and move files, delete, upload etc... just not rename... for the unknown classes, they should be defined above.

Public Class ContentEditorProvider 
            Inherits FileSystemContentProvider 
            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 StringByVal 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 Overloads Function CanUpload(ByVal path As StringAs Boolean 
                Return True 
            End Function 
            Public Overloads Function CanDelete(ByVal path As StringAs Boolean 
                Return True 
            End Function 
            Public Overrides Function CreateDirectory(ByVal path As StringByVal name As StringAs String 
                Dim RealPath As String = IO.FileSystem.ResolveDirectory(path) 
                Directory.CreateDirectory(RealPath & "\" & name) 
                Return path & name 
            End Function 
            Public Overrides Function CheckDeletePermissions(ByVal folderPath As StringAs Boolean 
                Return True 
            End Function 
            Public Overrides Function CheckWritePermissions(ByVal folderPath As StringAs Boolean 
                Return True 
            End Function 
            Public Overrides Function DeleteDirectory(ByVal path As StringAs 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 StringAs String 
                'HttpContext.Current.Response.Write(path) 
                DeleteFile = IO.FileSystem.ResolveDirectory(path) & GetFileName(path) 
                'HttpContext.Current.Response.Write(" - " & DeleteFile) 
                'HttpContext.Current.Response.End() 
                If File.Exists(DeleteFile) Then File.Delete(DeleteFile) 
                DeleteFile = String.Empty 
                Return DeleteFile 
            End Function 
            Public Overrides Function GetFile(ByVal url As StringAs System.IO.Stream 
                Dim RealPath As String = IO.FileSystem.ResolveURL(url) 
                Dim FullPath As String = RealPath & GetFileName(url) 
                If System.IO.File.Exists(FullPath) = True Then 
                    Dim File As Byte() = System.IO.File.ReadAllBytes(FullPath) 
                    GetFile = New MemoryStream(File) 
                Else 
                    GetFile = Nothing 
                End If 
                Return GetFile 
            End Function 
            Private Function GetName(ByVal path As StringAs String 
                GetName = IIf(path = NothingString.Empty, path.Substring(path.LastIndexOf("\"c) + 1)) 
                Return GetName 
            End Function 
            Public Overrides Function GetFileName(ByVal url As StringAs String 
                GetFileName = IIf(url = NothingString.Empty, url.Substring(url.LastIndexOf("/"c) + 1)) 
                Return GetFileName 
            End Function 
            Public Overrides Function GetPath(ByVal url As StringAs 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, IO.FileSystem.TranslateURL(VirtualPath), _FullPermissions, LoadFiles(SubDir), LoadDirectories(SubDir))) 
                Next 
                Return xDir.ToArray 
            End Function 
            Public Overrides Function MoveDirectory(ByVal path As StringByVal newPath As StringAs String 
                Dim sourceDirName As String = IO.FileSystem.ResolveDirectory(path) 
                Dim destDirName As String = IO.FileSystem.ResolveDirectory(newPath) 
                Try 
                    Directory.Move(sourceDirName, destDirName) 
                Catch exception As Exception 
                    Return exception.Message 
                End Try 
                Return String.Empty 
            End Function 
            Public Overrides Function MoveFile(ByVal path As StringByVal newPath As StringAs String 
                Dim n1 As String = GetFileName(path) 
                Dim n2 As String = GetFileName(newPath) 
                Dim d1 As String = IO.FileSystem.ResolveDirectory(path) 
                Dim d2 As String = IO.FileSystem.ResolveDirectory(newPath) 
                Dim f1 As String = d1 & n1 
                Dim f2 As String = d2 & n2 
                If Not File.Exists(f1) Then 
                    Return "FileNotFound" 
                End If 
                If File.Exists(f2) Then 
                    Return "NewFileAlreadyExists" 
                End If 
                Try 
                    File.Move(f1, f2) 
                Catch exception1 As UnauthorizedAccessException 
                    Return "NoPermissionsToMoveFile" 
                End Try 
                Return String.Empty 
            End Function 
            Public Overrides Function ResolveDirectory(ByVal path As StringAs 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 StringAs Telerik.Web.UI.Widgets.DirectoryItem() 
                If path <> "/" And 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 StringAs Telerik.Web.UI.Widgets.DirectoryItem 
                If path <> "/" And 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) 
                If Not DirInfo.Exists Then 
                    Return Nothing 
                End If 
                '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 StringByVal format As System.Drawing.Imaging.ImageFormat) As String 
                Dim RealPath As String = IO.FileSystem.ResolveURL(url) & GetFileName(url) 
                Dim newItemPath As String = IO.FileSystem.ResolveURL(url) & GetFileName(url) 
                Dim name As String = GetName(newItemPath) 
                Dim _path As String = IO.FileSystem.ResolveURL(url) 
                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 StringByVal name As StringByVal ParamArray arguments() As StringAs String 
                Dim FullName As String = IO.FileSystem.ResolveDirectory(path) & "\" & name 
                file.SaveAs(FullName) 
                Return path & name 
            End Function 
        End Class 

0
Fiko
Telerik team
answered on 17 Feb 2010, 10:37 AM
Hi Marc,

The problem comes from the fact that the newPath path passed to the MoveFile method (Rename and Move are the same operations) method is an absolute path (like C:\Dir\publicwwwroot\Dir) not  an virtual path (like /Dir1/SubDir/). The implemented in your content provider code that handles the moving a file requires the newPath parameter to be the virtual path of the new location of an item (moved or renamed). This path is calculated with the help of GetPath overridden method in the custom FileBrowserContentProvider. In order to fix the issue you need to rework the GetPath method as shown bellow:
Public Overrides Function GetPath(ByVal url As String) As String
    'ORIGINAL CODE:     GetPath = IO.FileSystem.ResolveURL(url)
 
    Dim dirPath As String = VirtualPathUtility.GetDirectory(url)
 
    Return dirPath
End Function

This method should return the parent directory of the an item. For example, if the passed url is this one: "/RootDir/Path1/image1.jpg" then the returned value should be "/RootDir/Path1/".

I hope this helps.

All the best,
Fiko
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Asked by
Dave
Top achievements
Rank 1
Answers by
Lini
Telerik team
Dave
Top achievements
Rank 1
Brad
Top achievements
Rank 2
Marc Messer
Top achievements
Rank 2
Fiko
Telerik team
Share this question
or