Fun with Telerik Rad Controls (Part 5/5)

by ManniAT 11. April 2009 08:40
Technorati-Tags:

This is the final part of a series of post about the telerik RadFileExplorer.

In the first part I showed the implementation of the backup logic, the second part was about integration with the a Custom File Content Provider and in the third part I showed the implementation of the server events. And in the fourth part I showed the restore process as well as some screenshots from the sample.

Now here I will show a few “tricks” I use to make the things easier – and I will show how the defaults are set.

First of all – I normally use a lot of these controls – and I use them on the most pages.
So on every page I would have to write:

<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>


This can be avoided by adding the control via web.config.

    <pages>
        <controls>
            <add tagPrefix="asp" namespace="System.Web.UI" assembly...
            <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly...
            <!-- avoid the need to register telerik assembly on every page with RadControls -->
            <add assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagPrefix="telerik"/>
        </controls>
    </pages>

With this setting do no longer have to add the register Tag on every page.

Now about the default settings. For these I also use web.config.

    <appSettings>
        <!-- default values for MyFileSystemProvider -->
        <add key="BackupURL" value="/XBackup"/>
        <add key="CopyInsteadOfMove" value="True"/>
        <add key="BackupEnabled" value="True"/>
        <!-- use this skin if no local override is done-->
        <add key="Telerik.Skin" value="Office2007"/>
    </appSettings>

With “appSettings” you can add custom entries to web.config. To read them later in code do something like

string strDoMove = WebConfigurationManager.AppSettings["CopyInsteadOfMove"] as string;
if (!string.IsNullOrEmpty(strDoMove)) {

If the entry does not exist the string is null. Else you have your settings loaded from the config file.

What is missing in the sample?
There are some points not completely implemented and for one point I have no solution at the moment.

  1. Delete of directories not implemented
    Here the files and subdirs must be collected an handled by backup.
    Currently I allow directory deletion only when the directory is empty.
  2. Restore of non existing directories
    This belongs to point 1 – and is the main reason why I did not implement the delete.
    My interface only shows files from the currently selected directory – so files from a deleted directory
    would never be visible.
  3. Clean up files from deleted directories
    Also this “problem” – but I guess a “automatically remove files older than” functionality covers this point.
    This I guess will be needed in some cases – I currently do this by hand.
  4. Move of protected directories
    Here is the “copy moved file back strategy” not working – this has to be done via “collecting files and folders.
    Currently I do not allow to move protected directories – even if “copy instead of move” is active.
  5. Rename of Files
    This is a real problem – since it is handled via “FileMove” – and I have no idea how to detect that the move is a rename
    .
edited after my brain is reawaken

It was a bit too late when I did this :)
The solution is very simple. If a file is renamed – it stays in the same directory while with a real move the directory changes.
So I have nothing to do than compare source and destination directory – if they are the same I avoid the “copy back” or disable the renaming if the file is protected.

public override string MoveFile(string path, string newPath) {
    bool bIsRename=    Path.GetDirectoryName(path) == Path.GetDirectoryName(newPath);
    if (m_lProtectedFiles.Contains(path, StringComparer.InvariantCultureIgnoreCase))    {
        if(bIsRename)    {    //no rename for protected files
            return ("File is protected and can't renamed!");
        }
        if (!DoCopy) {    //disallow move (copy is OK)
            return ("File is protected and can't be moved");
        }
    }
    string strRet = base.MoveFile(path, newPath);
    if (!DoCopy || strRet != string.Empty || bIsRename) {
        return strRet;        //copy not active or rename- or error in MoveFile run away :)
    }
    //copy the file back to the original location
    string strSource=HttpContext.Current.Server.MapPath(path);
    string strDestination=HttpContext.Current.Server.MapPath(newPath);
    File.Copy(strDestination, strSource);
    return strRet;
}

 

Last not least – this is a sample. Although I check for errors in the most places the code has not been tested for a longer time.
Further it is a “rough and dirty” solution without detailed planning. It makes the job – but I also guess there is a potential for optimization. Especially in the parameter handling I think something better could be done.

The approach of this project was to become familiar with the telerik RadFileExplorer and to prepare a first prototype for a customer.

What I did not tell – there is a HTTP handler in the project – this is used to download files and zipped directories.
But it has just a few lines of (commented) code – so everyone who is interested should take a look at it.

And the final question: Where is the code? Where are the binaries?

Telerik has a thing called code library. There I will post my solution. So check out – it shall be there in next days.
The reason for delay – I have to pack the code with a trial version of the controls, pack it – and post it there.

Telerik than screens the code – and if everything is OK it will be available to download.

Screening is finished – you can download the sample here

Tags:

telerik

Add comment




  Country flag
biuquote
  • Comment
  • Preview
Loading


Powered by BlogEngine.NET 2.0.0.0