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

Accessing FileContentProvider Object

5 Answers 100 Views
FileExplorer
This is a migrated thread and some comments may be shown as answers.
Samee Mir
Top achievements
Rank 1
Samee Mir asked on 09 Mar 2010, 06:28 AM
hi.
Can you please tell me how can i access the object of FileContentProvide with RadFileExplorer ?

Regards,
Samee Javaid        

5 Answers, 1 is accepted

Sort by
0
Dobromir
Telerik team
answered on 11 Mar 2010, 07:25 PM
Hi Samee,

By design, the RadFileExplorer control does not provide access to the content provider used. Could you please describe your scenario in details and / or provide a sample runnable project so we can investigate the case and get back to you with an appropriate solution?

Sincerely yours,
Dobromir
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
Lester
Top achievements
Rank 1
answered on 13 Mar 2010, 04:18 PM
Hi.

I am using your sample project about  DbContentProvider and need to connect the dbcontentprovider to pull data from many sqlservers.

I understand that in this assignation

RadFileExplorer1.Configuration.ContentProviderTypeName = typeof(Telerik.Web.Examples.DBContentProvider).AssemblyQualifiedName; 

You setup this property to future binding of the assembly. Works fine if like in the sample, the dbconnection is taken from a fixed setting in web.confg.

I need to this work dynamically, so, i need to pass the dbconnection in server code, i modified the code to send the new dbconnection in the searchpatterns property and works fine for the 1st time the sample runs

    protected void Page_Load(object sender, EventArgs e)
        {
                RadFileExplorer1.Configuration.SearchPatterns = new string[] {  "datasource=" + addressbox.text + ";......." };
                RadFileExplorer1.Configuration.ContentProviderTypeName = typeof(Telerik.Web.Examples.DBContentProvider).AssemblyQualifiedName;


Buf if in another page load if the addressbox.text have another value, the fileexplorer ignores this new value. I understand that the problem is that this controls dont have a refresh() method and looking in the sample code, you always only validate if the underlying placeholder values are null one time and in that case instantiate the required object, but if i change the contentprovidertypename, the underlaying objects are already instantiated ( are not null ) so this new value is ignored.

Line in the dbcontentprovider.cs file to check for dataserver instantiation

private DataServer DataServer 
        { 
            get 
            { 
                if (Object.Equals(_dataServer, null)) 
                { 
                    _dataServer = new DataServer(ServerAddress, ClientRoot ); 
                } 
                return _dataServer; 
            } 
        } 


If there is not a refresh() method that reload the entire contents (treeview & grid ), how can i subclass the radfileexplorer control to make the underlying internal variable that holds the instantiated object becomes null, or i assign it with a new instance of the custom content provider with a new address on it?

With this little piece of code i know the name of the protected variables, but looks like i am creating a 2nd object instead of overwriting the one i want

        protected class testFE : RadFileExplorer 
        { 
            public void X(  ) 
            { 
                 
                this.ContentProvider = null
            } 
        } 
 
        protected void Page_Load(object sender, EventArgs e) 
        { 
 
           RadFileExplorer1.Configuration.SearchPatterns = new string[] { "Datasource=" + Addressbox.text + "......." }; 
           RadFileExplorer1.Configuration.ContentProviderTypeName =              typeof(Telerik.Web.Examples.DBContentProvider).AssemblyQualifiedName; 
           testFE b = new testFE(); 
           b.X(); 
 


Any idea where can i achieve this refresh ?

LEster


0
Lini
Telerik team
answered on 15 Mar 2010, 03:36 PM
Hello Lester,

If you think that the DataServer object is not being updated properly after changing the connection string, try modifying the content provider code and add a check if the connection string has changed. For example:

private DataServer _dataServer;
private string _dataConnectionString;
private DataServer DataServer
{
    get
    {
        if (_dataConnectionString != ConnectionString)
        {
            _dataServer = null;
        }
        if (Object.Equals(_dataServer, null))
        {
            _dataConnectionString = ConnectionString;
            _dataServer = new DataServer(_dataConnectionString);
        }
 
        return _dataServer;
    }
}

This way the object will be recreated each time the ConnectionString changes.

Another solution can be to subclass the RadFileExplorer control override the ContentProvider property. This way you can check that you have the correct connection each time it is accessed and change it if necessary.

Regards,
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
Lester
Top achievements
Rank 1
answered on 15 Mar 2010, 06:01 PM
Hello. Lini

Any clue about the subclassng option ? that is what i am trying to do. But it creates me another object, cant use the instantiated control defined in the aspx part.


0
Lini
Telerik team
answered on 16 Mar 2010, 11:44 AM
Hello Lester,

Here is a sample class you can place in the App_Code folder of your web site and then use on the page instead of the original file explorer:

(place in App_Code)
namespace mynamespace
{
    public class myExplorer : Telerik.Web.UI.RadFileExplorer
    {
        protected override Telerik.Web.UI.Widgets.FileBrowserContentProvider ContentProvider
        {
            get
            {
                //add custom code here to check and update the content provider depending on connection string
                return base.ContentProvider;
            }
            set
            {
                base.ContentProvider = value;
            }
        }
    }
}

(sample usage in ASPX page)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="App_Code" Namespace="mynamespace" TagPrefix="myControls" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtm">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
<myControls:myExplorer ID="RadFileExplorer1" runat="server">
</myControls:myExplorer>
...

You can then reference the RadFileExplorer1 control in your code just the same as you would a normal telerik file explorer.

Regards,
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.
Tags
FileExplorer
Asked by
Samee Mir
Top achievements
Rank 1
Answers by
Dobromir
Telerik team
Lester
Top achievements
Rank 1
Lini
Telerik team
Share this question
or