This is a migrated thread and some comments may be shown as answers.

[Solved] FileBrowserContentProvider File Problems

4 Answers 208 Views
Editor
This is a migrated thread and some comments may be shown as answers.
BSV
Top achievements
Rank 1
BSV asked on 26 Aug 2009, 09:03 AM
Hi,

I am implemting a custom FileBrowserContentProvider for the ImageManager of the RadEditor. The purpose of this customer provider is to ensure the images inserted in the content of RadEditor can only we read if the user has logged on to the website and has sufficiant rights. Having that wish just a browsable virutal directory is not an option since the users are also located outside the domain.

During Implementation I found a very nasty problem which I can't solve.. I' am implemting the Telerik.Web.UI.Widgets.FileBrowserContentProvider interface. My problem is.. I build up all the stuff needed (see code below). But when using the ImageManager the tree on the left side is displayed perfectly. The content of the folders is also visible. But when clicking on a image in the content view of the folder only the content of the top image is displayed. 

For example I have the folder :

Windows Images 
    - Koala.jpg
    - Desert.jpg
    - Flower.jpg

When I click on Koala and Insert, the Koala picture is shown, and inserted in the RadEditor. When I click on Desert, the Koala picture is shown and inserted in the RadEditor. When I click on Flower the Koala picture is shown and inserted.

What is going on here? The generated urls for the Images are 100% correct and shown correctly when I invoke the url of the image directly. When I consult the debugger the content of the FIleItem aray is also correct. Please Help me!

Martijn,

PS. Keep up the good work!

 
        public override DirectoryItem ResolveDirectory(string path)  
        {  
            // First get the base path  
            string strBasePath = ConfigurationManager.AppSettings["MediaManagerPath"];  
 
            DirectoryInfo Directory = new DirectoryInfo(strBasePath + path);  
            FileInfo[] Info = Directory.GetFiles();  
            FileItem[] Files = new FileItem[Info.Length];  
            List<DirectoryItem> Subs = new List<DirectoryItem>();  
              
            for(int Index = 0; Index < Info.Length; Index++)  
            {  
                string ImageUrl = Security.GetWebsiteRootUrl(Context.Request) + "Gui/ContentManagement/File.aspx?Path=" + HttpUtility.UrlEncode(Info[Index].FullName.Replace(strBasePath, string.Empty));  
                string ImageThumbUrl = Security.GetWebsiteRootUrl(Context.Request) + "Gui/ContentManagement/File.aspx?Size=thumb&Path=" + HttpUtility.UrlEncode(Info[Index].FullName.Replace(strBasePath, string.Empty));  
                  
                Files[Index] = new FileItem(Info[Index].Name, Info[Index].Extension, Info[Index].Length, path, ImageUrl,string.Empty, PathPermissions.Delete | PathPermissions.Read | PathPermissions.Upload);  
            }  
                        
            // Ensure we replace the base path so it can not be used for reading the entire file system  
            return new DirectoryItem(Directory.Name, Directory.FullName.Replace(strBasePath, string.Empty), Directory.FullName.Replace(strBasePath, string.Empty), string.Empty , PathPermissions.Delete | PathPermissions.Read | PathPermissions.Upload, Files, Subs.ToArray());  
        }  
 
        public override DirectoryItem ResolveRootDirectoryAsTree(string path)  
        {  
            // First get the base path  
            string strBasePath = ConfigurationManager.AppSettings["MediaManagerPath"];  
 
            // Define all the variables   
            DirectoryInfo Directory = new DirectoryInfo(strBasePath + path);  
            FileItem[] Files = { };  
            DirectoryItem[] SubDirs = {};  
 
            DirectoryInfo[] SubDirectories = Directory.GetDirectories();  
            List<DirectoryItem> Subs = new List<DirectoryItem>();  
 
            foreach (DirectoryInfo Info in SubDirectories)  
            {  
                Subs.Add(ResolveDirectory(Info.FullName.Replace(strBasePath, string.Empty)));                      
            }  
 
            // Ensure we replace the base path so it can not be used for reading the entire file system  
            return new DirectoryItem(Directory.Name, Directory.FullName.Replace(strBasePath, string.Empty), Directory.FullName.Replace(strBasePath, string.Empty), string.Empty, PathPermissions.Delete | PathPermissions.Read | PathPermissions.Upload, Files, Subs.ToArray());  
        } 


 

4 Answers, 1 is accepted

Sort by
0
Fiko
Telerik team
answered on 28 Aug 2009, 10:00 AM
Hello Martijn,

The behavior that you experience is the expected one in your case. Please note that the items' pats in the file explorer need to be unique. The item's path property identifies an item and you need to build unique file path in the ResolveDirectory method or pass a string.Empty value to the location parameter in the FileItem's constructor :

Files[Index] = new FileItem(Info[Index].Name, Info[Index].Extension, Info[Index].Length, string.Empty, ImageUrl, string.Empty, PathPermissions.Delete | PathPermissions.Read | PathPermissions.Upload); 

As a result of the code above, the file's path will be : THE_PARENT_FOLDER_PATH/Info[Index].Name.
Additionally, I recommend you to change the Directory variable name to dirInfo for example. This is not related to the problem that you experience, but a class with the same name already exists and this may cause some mistakes, that are hard to be localized.

I hope this helps.

Sincerely yours,
Fiko
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
BSV
Top achievements
Rank 1
answered on 29 Aug 2009, 06:32 AM
Hello Fiko

Your solution was excellent! Thanks for information!

About the naming of variables, this was some quick code to show the problem, normally I am using the Hungarian C (Cammel Case) notation. But you're right, it can be hard to solve!

Martijn
0
BSV
Top achievements
Rank 1
answered on 01 Sep 2009, 07:34 AM
Hi Again,

I ran into a new problem, everything is running smooth, I can delete / create / view folders wihtout any problems.. However.. uploading files is not working. Even before the server is called I get a client sided message "could not write to the folder" - and then the name of the folder I just selected containing the file to upload."

I set the path of the image manager as follows:

            rdContentEditor.ImageManager.ViewPaths = new string[] { "Images\\" };  
            rdContentEditor.ImageManager.DeletePaths = new string[] { "Images\\" };  
            rdContentEditor.ImageManager.UploadPaths = new string[] { "Images\\" };  
            rdContentEditor.ImageManager.ContentProviderTypeName = typeof(BSV.CRM.Web.Domain.ContentManagement.FileBrowserContentProvider).AssemblyQualifiedName;  
            rdContentEditor.ImageManager.MaxUploadFileSize = 1024 * int.Parse(ConfigurationManager.AppSettings["maxRequestLength"]); 

What do I wrong here?

Martijn
0
Fiko
Telerik team
answered on 02 Sep 2009, 01:15 PM
Hello BSV,

This error occurs because the default value of the PathSeparator (in the content provider) property id '/'. In your case you need to override this property to return '\\' symbol:

public override char PathSeparator 
    get 
    { 
        return '\\'
    } 

Then, I recommend you check whether the CheckWritePermissions function (in the content provider) returns the appropriate value and override its behavior in order to cover your requirements. At the end you need to override the StoreFile function :

public override string StoreFile(UploadedFile file, string path, string name, params string[] arguments) 
    // The code that saves the file ; 
    .... 
    .... 
 
    return path_to_file; 


I hope this helps.

All the best,
Fiko
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Editor
Asked by
BSV
Top achievements
Rank 1
Answers by
Fiko
Telerik team
BSV
Top achievements
Rank 1
Share this question
or