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

About FileBrowserContentProvider

7 Answers 293 Views
FileExplorer
This is a migrated thread and some comments may be shown as answers.
ManniAT
Top achievements
Rank 2
ManniAT asked on 08 Apr 2009, 08:29 PM
Hi,

my approach is to backup files when a user loads up a file which already exists in the filesystem.
I took a look at the online documentation as well as in the DBContentProvider - but without meaningful documentation it would really mean a lot of time to figure out what parameters to pass where.

And if I see constructors with 7 parameters like for DirectoryItem it is pretty hard to develop something without documentation.
And by the way - the example (DBContentProvider) deals with slashes - as well for url's (normal) as for filepaths (where I would use backslashes for the file system).
A lot of parameter are simply give as string.Empty...

So the idea of writing an own provider is good - and since the FileExplorer does not offer server methods like the RadUpload to handle uploading (storing) files it seems to be the only possible method.
BUT - due to the poor documentation it is impossible for me to build such a thing within a timeframe that seems to be acceptable.

Is there any sample for a filesystem provider?

The approach is nothing less or more than:
If a file gets deleted - create a backup copy.
If a file will be overwritten - create a backup copy.

In http://www.telerik.com/community/forums/aspnet-ajax/file-explorer/select-a-file-in-code.aspx#792727 someone asked a member to provide code in the Code Library - but the Library does not even have a section for FileExplorer.

Regards

Manfred

7 Answers, 1 is accepted

Sort by
0
Shaun Peet
Top achievements
Rank 2
answered on 08 Apr 2009, 09:38 PM
Hello Manfred,

The first thing I'd recommend is getting a copy of .NET Reflector:

Using that, you'll be able to open the Telerik.Web.UI.dll and have a look at how Telerik implements their FileSystemContentProvider so that you know which methods to override.  I've been using my own customized provider for a while that allows my users to upload zip files which are then extracted & deleted on the server, and posted the code for it here:

The two functions (I'm a VB programmer) that you'll need to override are the StoreFile and the DeleteFile functions.  The DeleteFile one should be fairly easy, something like:

 
    Public Overrides Function DeleteFile(ByVal path As StringAs String 
        ' Create a backup of the file somewhere 
        IO.File.Copy(path, "/backups/" & path) 
        ' Delete the file 
        Return MyBase.DeleteFile(path) 
    End Function 
 
 

StoreFile will be a little trickier, but not too bad.  Just check if the file exists already and if so, write the old one to your backup location prior to executing MyBase.StoreFile.  If you're a C# guy then have a look at www.codechanger.com to convert the VB to C#.  Hope that helps,

Shaun.
0
ManniAT
Top achievements
Rank 2
answered on 08 Apr 2009, 09:54 PM
Thank you Shaun,

I got it.
Although I have access to the source code of the controls I did not even think about that Telerik also has to have such a provider.
OK - with this the things are easy!

And since  Telerik.Web.UI.Widgets.FileSystemContentProvider  is a public class I only have to overload the two methods I need to change.

The operations itself are no problem.

And just to complete this task - the functions are a bit more complicated because they do:
a.) Create a copy of the file
b.) remember where it has been as well as when it was deleted (overwritten)
c.) hold some kind of stack for the latest 3 versions.

But it is not really a problem to code this functionality.
My only problem was that I was to tired (about 12pm here in austria) to think about the fact that Telerik must also have such a provider :)

So thanks again Shaun

Manfred
0
Shaun Peet
Top achievements
Rank 2
answered on 08 Apr 2009, 10:43 PM
Glad to help.  Sleep well!
0
Amr Saafan
Top achievements
Rank 2
answered on 09 Apr 2009, 03:19 PM
Hi,

I need to know how to implement FileBrowserContentProvider class with sample code.

0
ManniAT
Top achievements
Rank 2
answered on 10 Apr 2009, 01:21 AM
Hi,

as posted here http://www.telerik.com/community/forums/aspnet-ajax/file-explorer/section-in-code-samples.aspx
I currently write a code sample which includes (beside other things):
File copy instead of move - done via FileBrowserContentProvider
File backup (on delete / overwrite) - also done via FileBrowserContentProvider.

Tomorrow I've public holidays - but I guess on saturday the example should be ready.
Till then I guess that telerik gave an answer to the other post - and I know where to post it.

By the way - the example is about 70% ready - I does what it is made to do.
Now only final documentation and some clearing is missing.

If this takes to long for you - I suggest to follow Shaun's tip with reflector.

Regards

Manfred
0
AppliedHCS
Top achievements
Rank 1
answered on 19 Dec 2012, 09:07 AM
Hello ManniAT/ Shaun / Telerik Team

I want to use FileBrowserContentProvider.

Using RadFileExplorer, I want to communicate with Database. When i am creating any New Folder/Sub Folder at that time i want name of that folder and also want to fire insert Query. So where i can code that ? Also how to retrieve this name from Database during page load.

Another, during page load i want to Bind TreeView according to user
For Example, User1 has uploaded file1,file3 under Test1 Folder and  User2 has uploaded file2 under Test1 Folder which is same folder.
So user1 can view only his file under Test1 Folder.

Please help me with above issue. Sample code will be more helpful.

Thanks




0
Fiko
Telerik team
answered on 21 Dec 2012, 01:27 PM
Hello Parag,

In order to configure RadFileExplorer to work with data base you can both implement your own custom content provider, or use the one available in the following code library: Connect RadFileExplorer to an SQL databse.

You can catch the name of the newly created folders, uploaded files as well as if the user is renaming the already existing ones, in the event-handler of the ItemCommand server-side event:
protected void Page_Load(object sender, EventArgs e)
{
    RadFileExplorer1.ItemCommand += new Telerik.Web.UI.RadFileExplorerEventHandler(RadFileExplorer1_ItemCommand);
}
 
protected void RadFileExplorer1_ItemCommand(object sender, Telerik.Web.UI.RadFileExplorerEventArgs e)
{
    string newName;
 
    switch ((e.Command))
    {
        case "UploadFile":
            newName = e.Path.Substring(e.Path.LastIndexOf("/") + 1);
            break;
 
        case "CreateDirectory":
            newName = e.NewPath;
            break;
 
        case "MoveFile": //Fired both if a file is moved or renamed
            newName = e.NewPath.Substring(e.NewPath.LastIndexOf("/") + 1);
            break;
 
        case "MoveDirectory": //Fired both if a folder is moved or renamed
            newName = e.NewPath.Substring(e.NewPath.LastIndexOf("/") + 1);
            break;
    }
}

Regarding the files which are visible for the different users, I would suggest you to review the following KB article: Hide certain directories and files in RadFileExplorer.

I hope you find this information helpful.

Regards,
Fiko
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Tags
FileExplorer
Asked by
ManniAT
Top achievements
Rank 2
Answers by
Shaun Peet
Top achievements
Rank 2
ManniAT
Top achievements
Rank 2
Amr Saafan
Top achievements
Rank 2
AppliedHCS
Top achievements
Rank 1
Fiko
Telerik team
Share this question
or