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

Bind FileSystemContentProvider to database

15 Answers 292 Views
FileExplorer
This is a migrated thread and some comments may be shown as answers.
L uke
Top achievements
Rank 1
L uke asked on 24 Sep 2009, 09:26 AM
I have overloaded methods and succesfully get the folders and files stored in database table. Now I`m trying to implement deleting files, but when delete first executes GetPath function which always crush the control.
What should it return, when on input I get "/Folder A/File 12", on output I have tried
null
string.Empty
"Folder A/File 12"
"/Folder A/"
"/Folder A" - in this case I get message that there are no permissions?
"/Folder A/File 12/"

Of course none of this locations exist physically, they reflect data in my table.

15 Answers, 1 is accepted

Sort by
0
Fiko
Telerik team
answered on 28 Sep 2009, 03:01 PM
Hi Luke,

I believe that this online demo will be of help. For your convenience I have attached the implementation of the Telerik.Web.Examples.DBContentProvider class to this thread.

I hope this helps.

Best wishes,
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
Luca Fumagalli
Top achievements
Rank 1
answered on 15 Oct 2009, 03:20 PM
Sorry, I want to use DBContentProvider.cs and DataServer.cs to fill a File Explorer control.

I need an example how to call this method in the paghe that contains the FileExplorer Control.

Thanks, Luca.
0
Fiko
Telerik team
answered on 21 Oct 2009, 11:50 AM
Hi Luca,

I am not quite sure that I understood your scenario. The provided files in this example are intended to be used to provide content to the RadFileExplorer. You could use them for different purposes, but in this case you need to modify the files to fit your requirements. This task, however, is not related to our controls and it is beyond our support.
If you have any problems using the RadFileExplorer control with the DBContentProvider, please open a new support ticket and send a working project, including a detailed explanation of the desired behavior. I will check it and do my best to provide a solution.

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
Gerrit du Preez
Top achievements
Rank 1
answered on 18 Feb 2010, 10:19 PM
Hi there

I am using the DBContentProvider to store files in a database.  Everything works nicely.

I would like to extend the functionality by adding properties to a document, also stored in the same table as the file itself.  In my database, I have e.g. a column for Author and DocumentVersion as well as the column containing the file content and the other columns necessary to store files in a database - MimeType, IsDirectory etc.

In the FileExplorer, I added a context menu item called "Properties" so, when I have uploaded a document, I can right click on it, click on the added "Properties" ContextMenu item thats open a RadWindow with the path of the specific document in the QueryString and a form where I can add the Author and Document version data.

This is all working, but now I want to submit the form and update the correct database row with the additional properties submitted in the form.  I assume I can get that by using the path I get from the FileExplorer (selectedItem.get_path() Client Side method) placed in the QueryString of the RadWindow and query the database to find the item that matches it.  It is a bit tricky, for the whole path is not stored with the item itself in the database.

Question 1:
What I would like to know is if there is an easier way to get e.g. the ID of the table row (primary key) from the FileExplorer itself.  I get the path, but I would like to get the primary key of the table row the specific document is stored in.  Can this be done and any ideas as to how to do it?

Question 2:
Since I store the documents as well as additional properties in a database, is there a way to display these properties in additional grid columns in the FileExplorer itself, e.g. next to each document, the Author or DocumentVersion etc. All of this is part of the same database row and would be easy to  query, the question is, how to display it in the RadGrid that is part of the FileExplorer?

Your help would be much appreciated.

Greetings

Gerrit
0
Gerrit du Preez
Top achievements
Rank 1
answered on 18 Feb 2010, 10:21 PM
Hi there

I managed to get the ID by using the DataServer.cs class.

Will appreciate it if you can still advise me on Question 2 though.

Greetings

Gerrit
0
Fiko
Telerik team
answered on 24 Feb 2010, 11:05 AM
Hi Gerrit,

In reference to your question:
  • In the implementation of the DBContentProvider the ID of an item is retrieved by its path. In your case you can change and pass the ID (primary key) of the item when you construct the item instead of passing the full URL.
    FileItem newFileItem = new FileItem(name,
                        Path.GetExtension(name),
                        (int)childRow["Size"],
                        itemFullPath,
                        GetItemUrl(childRow["ItemID"].ToString()),
                        string.Empty,
                        GetPermissions(itemFullPath)
                        );

    Then you can get the ID by calling the get_url() of the FileBrowserItem object on the client. For example in the OnClientFileOpen handler:
    <script type="text/javascript">
        function OnClientFileOpen(oExplorer, args)
        {
            var item = args.get_item();
            alert(item.get_url());
        }
    </script>
  • "...is there a way to display these properties in additional grid columns..."
    I believe that this online demo will be of help.

I hope this helps.

Kind 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
Gerrit du Preez
Top achievements
Rank 1
answered on 02 Mar 2010, 09:08 AM
Hi Fiko

Thanks for the reply. Will check it out.

Greetings

Gerrit
0
Gerrit du Preez
Top achievements
Rank 1
answered on 09 Mar 2010, 03:01 PM
Hi there

"...is there a way to display these properties in additional grid columns..."
I believe that this online demo will be of help.

I had a look at the demo and got it going when using the file explorer for files stored physical files (as in the demo).  However, I would like to use this functionality while storing the files in a database.

I have a project where I use the DBContentProvider and there are some additional database fields I would like to show in the grid of the file explorer.  The example you referred to, extract information from the physical files, like date and owner.  In the same way I would like to show data, but in this case, extracted from the database row where the rest of the file information is stored.

In my project I added a context menu for "Properties", so after uploading a file to the explorer, I can right click on the file and find the "Properties" item in the context menu.  This takes me to a form where I can add additional information like a description, author etc. and when subitted, stored in the same database row as the file content itself.

I would like this information, e.g. the description, to display in the grid of the file explorer as well.

Any ideas as to how this can be achieved?

Thanks

Gerrit
0
Lini
Telerik team
answered on 12 Mar 2010, 10:38 AM
Hello Gerrit,

You can add additional columns to the grid as shown in the online demo - more specifically the AddGridColumn method in the code file. To populate the new column with data, you need to modify the ResolveDirectory / ResolveRootDirectoryAsTree methods in your DBContentProvider class and add a new attribute to the FileItem / DirectoryItem objects after you create them. This is shown in the CustomColumnsContentProvider class in the online demo. In your case you already have a custom content provider, so you simply need to add the .Attributes.Add(...) call to the right place and use the data from the DB.

All the best,
Lini
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
Gerrit du Preez
Top achievements
Rank 1
answered on 18 Jun 2010, 10:55 AM
Hi there

I have a RadFileExplorer linked to a database, based on your online example.

When I delete a folder, only the the selected folder gets deleted, but the child folders and files still remain as entries in the database.

When using the RadFileExplorer with files and folders in the file system of a server, all the child items gets automatically deleted when a folder is deleted, as expected.  This does not happen when usings a database. I assume some extra code is needed to loop through the child items when deleting a folder when the RadFileExplorer is linked to a database.

Any advise on this?

Greetings

Gerrit 
0
Lini
Telerik team
answered on 21 Jun 2010, 11:27 AM
Hello Gerrit,

The DB content provider in the example will not cascade delete statements - you can find the code for the delete operation in the DataServer.cs file (/App_Code/Editor/DataServer.cs in the live demos web site):

(line 153)
public void DeleteItem(string path)
...

If you have experience with SQL, you can create a Cascading Referential Integrity Constraint on the table where the files and folders are stored and use "ON DELETE CASCADE" for the references clause. I am sure that similar cascading options exist with other RDMBSs as well (e.g. Oracle, MySQL). You can also implement a .NET recursive solution  that selects related rows and deletes them as well.

Greetings,
Lini
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
Rohan
Top achievements
Rank 1
answered on 09 May 2012, 12:45 PM
Hi fiko,

I want to user Custom file content provider for File Explore . I don't know how to use ,how to implement this i am confusing because i have different table structure that you specified in example . please provide any easy way to implement FileSystemContentProvider.

0
Dobromir
Telerik team
answered on 14 May 2012, 09:02 AM
Hi Rohan,

You can find detailed information regarding the FileBrowserContentProvider class in the following help article:
Using custom FileBrowserContentProvider

All the best,
Dobromir
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Prashanth
Top achievements
Rank 1
answered on 16 Sep 2013, 12:17 PM
hi
I have created a asp.net ajax website by following instructions in www.telerik.com/help/aspnet-ajax/fileexplorer-getting-started.html.
and i want to know how to save the folder and files into database . i am not able to understand from where he is creating the folders and saving in a path. 
Can u please help 
0
Marin Bratanov
Telerik team
answered on 18 Sep 2013, 12:08 PM
Hello,

Have you examined the resources my colleagues have linked previously in the thread?
http://www.telerik.com/help/aspnet-ajax/fileexplorer-custom-filebrowsercontentprovider.html
http://demos.telerik.com/aspnet-ajax/fileexplorer/examples/server-sideapi/dbfilebrowsercontentprovider/defaultcs.aspx
They explain how to use custom providers for your files. What the exact file structure is and how it is created depends on the developer and their project, which is why these providers are custom. By default, RadFileExplorer shows files and folders from within the web application, as designated by its ViewPaths, UploadPaths and DeletePahts properties under Configuration. You can see a prime example of such basic configuration in this demo:
http://demos.telerik.com/aspnet-ajax/fileexplorer/examples/server-sideapi/initialpathandpaging/defaultcs.aspx
Once you download the demos project you can also examine it locally.
You may also find useful the RadFileExplorer Code Library section which shown an SQL provider in detail:
http://www.telerik.com/community/code-library/aspnet-ajax/file-explorer/connect-radfileexplorer-or-radeditor-to-a-sql-databse.aspx


Regards,
Marin Bratanov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
FileExplorer
Asked by
L uke
Top achievements
Rank 1
Answers by
Fiko
Telerik team
Luca Fumagalli
Top achievements
Rank 1
Gerrit du Preez
Top achievements
Rank 1
Lini
Telerik team
Rohan
Top achievements
Rank 1
Dobromir
Telerik team
Prashanth
Top achievements
Rank 1
Marin Bratanov
Telerik team
Share this question
or