Path Outside Web application

15 posts, 0 answers
  1. Mossie
    Mossie avatar
    6 posts
    Member since:
    Jun 2012

    Posted 31 Jul 2012 Link to this post

    Ive been using the FileExplorer successfully when the folder(s) is in the web application.   Im now working on an application where the folder is outside the web application i.e. c:\test .  I can list  the folders/files using GetDirectories and GetFiles in System.IO.  For consistency id like to use the FileExplorer control.  Is this possible and can you point me to a sample - I was unable to find one.
  2. Vessy
    Admin
    Vessy avatar
    1389 posts

    Posted 01 Aug 2012 Link to this post

    Hi Francis,

    The reason why you could not access the files when they are placed in a physical path outside the project, is that by design RadFileExplorer uses virtual paths. That means that only files(and folders) inside the project root folder ( "~/") can be accessed.

    There is a way to implement your custom FileBrowserContentProvider, where you declare what the path type would be. An example of such custom content provider is available in this Knowledge Base article: Use RadFileExplorer with physical and shared folder's paths.

    Additional information regarding the FileBrowserContentProvider abstraction is available in the following help article:
    Using custom FileBrowserContentProvider

    All the best,
    Veselina
    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Martin Roussel
    Martin Roussel avatar
    246 posts
    Member since:
    Jan 2010

    Posted 14 Sep 2012 Link to this post

    Vesi,

    I managed to make my FileExplorer work with shared paths (thanks to the Base Article you mentioned) but Im still facing one issue. In my case, im retrieving the Viewpaths from a database (not a config file like the sample). Im retrieving the dataset in my aspx.cs file (Page_Load), just before setting the RadFileExplorer1.Configuration.x properties.

    The problem is I want to pass the dataset to the CustomFileSystemProvider.cs class (or worse case, my DB parameters so I can requery it once in there) but I cant figure out to do it correctly. Right now, im using a really ugly way by using the RadFileExplorer1.Configuration.SearchPatterns property and filling that string array with my dataset rows. It works but I end up unable to specify extension filtering. By looking at the class constructor, it seems I can use the variables: context, searchPatterns, viewPaths, uploadPaths, deletePaths, selectedUrl, selectedItemTag.

    Is there another property I can use or other way to pass my parameters? I also have the same issue to pass the parameters to the FileSystemHandler.ashx handler (this time I can use Context.Request.QueryString but I dont like requerying the database...i would like to pass the dataset i already have).

    Please let me know if I have to send my code.

    TIA
  5. Vessy
    Admin
    Vessy avatar
    1389 posts

    Posted 18 Sep 2012 Link to this post

    Hi Francis,

    A possible way to achieve the desired scenario  is to pass your dataset as a value of a field on the page in the PageLoad server event. After that you could access this value from the FileBrowserContentProvider's constructor or in the handler (FileSystemHandler.ashx) through the HttpContext object.

    More information on how to achieve the above mentioned scenario is available in the following KB article: Get reference to the Page object inside a custom FileBrowserContentProvider.

    Greetings,
    Vesi
    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.
  6. Martin Roussel
    Martin Roussel avatar
    246 posts
    Member since:
    Jan 2010

    Posted 18 Sep 2012 Link to this post

    Vesi,

    your answer seems to put me on the right track since I can now access my page controls and their content from the Provider class. However, all examples I can find seem to use the FindControl property to access the needed values.  Ex :

    int newWidth = 0;
    TextBox tbWidth = _pageContainsRadFileExplorer.FindControl("TextBoxWidth") as TextBox;
    newWidth = int.Parse(tbWidth.Text);

    My question: Am I forced to put my values in a control and access them in such way? Seems for me to be a overkill. Is there a way I can access public members of the class of my page? Or some other cleaner way? I cant find out how to cast my Page variable (_pageContainsRadFileExplorer)

    Thanks again

    Martin
  7. Vessy
    Admin
    Vessy avatar
    1389 posts

    Posted 21 Sep 2012 Link to this post

    Hi Francis,

    You could access every HTML element if its runat="server" property is set. After that, in the code-behind, when accessing this element, you will need to cast it depending on the control's type.

    For instance, if you are using an <input type="text"> element, it has to be cast to an HtmlInputControl type. It could be accessed in a similar way:
    ASPX:
    <input type="text" id="TextBoxWidth" runat="server"/>

    CS:
    var tbWidth = _pageContainsRadFileExplorer.FindControl("TextBoxWidth") as HtmlInputControl;
    newWidth = int.Parse(tbWidth.Value);

    I hope this helps.

    All the best,
    Vesi
    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.
  8. Martin Roussel
    Martin Roussel avatar
    246 posts
    Member since:
    Jan 2010

    Posted 21 Sep 2012 Link to this post

    Vesi,

    Thanks again..made some progress. Only thing im hitting now is in the FileSystemHandler.ashx. It seems like I cant use the HttpContext in there. Unlike CustomFileProvider.cs, it always returns null:

    Page _pageContainsRadFileExplorer = HttpContext.Current.Handler as Page; //always returns null

    Here's a more detailed view of the variable that might help (taken from VS "Immediate Window"):

    ?HttpContext:
    System.Web.HttpContext
        base {object}: object
        Current: {System.Web.HttpContext}

    ?HttpContext.Current:
    {System.Web.HttpContext}
        AllErrors: null
        Application: {System.Web.HttpApplicationState}
        ApplicationInstance: {ASP.global_asax}
        Cache: {System.Web.Caching.Cache}
        CurrentHandler: {FileSystemHandler}
        CurrentNotification: 'HttpContext.Current.CurrentNotification' threw an exception of type 'System.PlatformNotSupportedException'
        Error: null
        Handler: {FileSystemHandler}
        IsCustomErrorEnabled: false
        IsDebuggingEnabled: true
        IsPostNotification: 'HttpContext.Current.IsPostNotification' threw an exception of type 'System.PlatformNotSupportedException'
        Items: Count = 2
        PreviousHandler: null
        Profile: {System.Web.Profile.DefaultProfile}
        Request: {System.Web.HttpRequest}
        Response: {System.Web.HttpResponse}
        Server: {System.Web.HttpServerUtility}
        Session: null
        SkipAuthorization: false
        Timestamp: {9/21/2012 1:57:15 PM}
        Trace: {System.Web.TraceContext}
        User: {System.Security.Principal.WindowsPrincipal}

    ?HttpContext.Current.Handler:
    {FileSystemHandler}
        [FileSystemHandler]: {FileSystemHandler}
        IsReusable: false


    btw why you call me Francis?
  9. Vessy
    Admin
    Vessy avatar
    1389 posts

    Posted 26 Sep 2012 Link to this post

    Hi Martin,

    Please, accept my sincere apologies for mixing your name up for so many times, I guess I have misled myself because of the first post in the tread.

    Regarding your question, I made a research and it turned out to be a widely spread issue. Actually, you are not able to access the page itself from a Generic Handler, because it is created after the handler tries to get an instance of it.

    As a workaround for this behavior, I could suggest you to access the page in the code behind and to pass the desired value as a parameter to the current session:

    CS:
    var tbWidth = _pageContainsRadFileExplorer.FindControl("TextBoxWidth") as HtmlInputControl;
    newWidth = int.Parse(tbWidth.Value);
    Session["TextBoxWidthValue"] = newWidth ;

    In order to access the session in your ashx file you need to implement IRequiresSessionState interface in your handler class:

    ASHX:
    public class Handler : IHttpHandler, System.Web.SessionState.IRequiresSessionState
    {
       ...
    }

    Then you can access the session as context.Session. Here context is the object of class HttpContext, which is passed as a parameter in ProcessRequest method:

    ASHX:
    public void ProcessRequest(HttpContext context)
    {
        context.Session["TextBoxWidthValue"]; //will return the value passed from the code-behind
    }


    All the best,
    Vesi
    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.
  10. Martin Roussel
    Martin Roussel avatar
    246 posts
    Member since:
    Jan 2010

    Posted 26 Sep 2012 Link to this post

    thanks alot for your time Vesi, it works.

    MArtin
  11. Martin Roussel
    Martin Roussel avatar
    246 posts
    Member since:
    Jan 2010

    Posted 15 Apr 2013 Link to this post

    Hi, ive noticed that the code from the Base article (in my integration anyway) doesnt seem to support paths pointing directly to  specific files (ex: "C:/file1.jpg") as all example Ive seen use only directories. I would like my FileExplorer to support this so I can restrict access to the other files from the same folder. Can someone please help enhance the library code? What im trying seems to always fails at some point or another.

    TIA

    Martin
  12. Vessy
    Admin
    Vessy avatar
    1389 posts

    Posted 18 Apr 2013 Link to this post

    Hi Martin,

    The described scenario is not supported by the FileExplorer out-of the box and you could pass only folder paths to its ViewPaths property. Nevertheless, you could use the approach described in this KB article in order to hide all files, except from the desired one, so you can restrict the access of the user to the other files of the folder.

    I hope this would be helpful for you.

    Kind regards,
    Veselina Raykova
    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.
  13. Martin Roussel
    Martin Roussel avatar
    246 posts
    Member since:
    Jan 2010

    Posted 25 Apr 2013 Link to this post

    Hi again Vesi,

    Regarding your workaround you provided in this thread on September 26th 2012, that workaround worked for me until now. The reason is I created a "user portal" page where the user can add different widgets (user controls) as many as he wants on the same page, with the help of the RadDock control. Two of my selectable widgets contain one RadFileExplorer in each. The problem is when I add these two widgets on the same page (since im using the same System Provider/Handler classes for both Explorers), both controls compete for the same Session variable and overwrite the viewpaths of the other.

    Im looking for a solution to handle this and, if possible, the possibility to  also have multiple instance of the same widget on the same page. Can you help?

    TIA

    Martin
  14. Vessy
    Admin
    Vessy avatar
    1389 posts

    Posted 30 Apr 2013 Link to this post

    Hi Martin,

    Could you clarify what is the exact value you want to pass to the generic handler and what is the main purpose you want to do so? Basically, the scenario you are trying to achieve is pretty complicated and cannot be achieved without using of "hacks" in the FileExplorer. The only remaining workaround which I could suggest you is similar to the one, used by you before (by passing the values through the SearchPattern values). You can pass the ID of the current FileExplorer to its ViewPaths property in order to access it in the custom content provider and make the other configurations depending on this ID:
       - Pass the current FileExplorer ID through the FileExplorer's ViewPaths:
    protected void Page_Load(object sender, EventArgs e)
    {
        RadFileExplorer1.Configuration.ViewPaths = new string[] { "~/Filters", "***RadFileExplorer1***" }; //Pass the current FileExplorer ID
        RadFileExplorer1.Configuration.ContentProviderTypeName = typeof(CustomContentProvider).AssemblyQualifiedName;
    }

       - Access the code in the custom content provider and skip the folder with the passed name in the RasolveRootDirectoryAsTree() methods:
    public class CustomContentProvider : FileSystemContentProvider
    {
        private string Code;
        public CustomContentProvider(HttpContext context, string[] searchPatterns, string[] viewPaths, string[] uploadPaths, string[] deletePaths, string selectedUrl, string selectedItemTag)
            : base(context, searchPatterns, viewPaths, uploadPaths, deletePaths, selectedUrl, selectedItemTag)
        {
            Code = ViewPaths[viewPaths.Length - 1].Substring(ViewPaths[viewPaths.Length - 1].LastIndexOf("/")+1).Replace("***", "");
            ViewPaths[ViewPaths.Length - 1] = "***TOSKIP***";
        }
      
        public override Telerik.Web.UI.Widgets.DirectoryItem ResolveRootDirectoryAsTree(string path)
        {
            //Skip the folder(s) that we do not want to see
            if (path == "***TOSKIP***")
                return null;
            else
            {
                return base.ResolveRootDirectoryAsTree(path);
            }
        }
    }

    Note, that this scenario is not supported by the control and since it is a kind of hack and may lead to some unexpected issues.

    Additionally, I just want to recommend you on more time to filter the desired files, listed in you FileExplorer instead of pointing the ViewPaths to them in a custom ContentProvider. This will make most of your other requirements much more easier to be implemented.

    Kind regards,
    Veselina Raykova
    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.
  15. Martin Roussel
    Martin Roussel avatar
    246 posts
    Member since:
    Jan 2010

    Posted 06 May 2013 Link to this post

    Hi Veselina,

    the value I want to pass is the viewpaths array of the exact user control instance calling the handlers. Since im using Session variables, I used your new workaround to store the shared data in a session variable having the same name as the ClientID (unique) of its caller control...roughly like this:

    string strSessionViewPath = RadFileExplorer1.ClientID + "_viewpath";

    if (strViewPath != "")
    {         
    Session[strSessionViewPath] = strViewPath;
    }

    viewPaths[viewPaths.Length - 1] = "***" + strSessionViewPath + "***";

    RadFileExplorer1.Configuration.ViewPaths = viewPaths;

    It seems to work correctly except when I have multiple instances of the same control on the same page (but strangely, issue occurs in Thumbnail View mode only): Browsing the directories refreshes the content of other controls of the same type. I had the same issues with two different types of controls containing a FileExplorer but issue was solved by using different ID names for each FileExplorer.

    Ill try to create a ticket with a runnable sample of the issue. UPDATE: ticket #690203 is now created.


    TIA

    Martin
  16. Vessy
    Admin
    Vessy avatar
    1389 posts

    Posted 08 May 2013 Link to this post

    Hi Martin,

    I have already answered your support ticket on the subject, and since there are a few code snippets in my reply I would suggest to continue our conversation in the ticket tread.

    Please, feel free to re-post my reply if you do not mind your code to be published and you would like to share the explanations in the ticket with the Telerik community.

    Kind regards,
    Veselina Raykova
    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017