Telerik Forums
UI for ASP.NET AJAX Forum
1 answer
222 views
Hi,
I have recently started using the FileExplorer control for a file manager within our backend. Our system works with absolute paths (instead of relative), hence I implemented a custom FileBrowserContentProvider.

Everything works fine except for one single thing: when renaming a file from, for example, 'NewFileName.jpg' to 'File1.jpg', the file is renamed to 'NewFileName.jpgFile1.jpg' (the old file name and new file name are concatenated). This issue is only present withfile renaming. File move, directory move and directory rename all work fine. The parameter newPath in the MoveFile function within the content provider is already being supplied in a wrong manner (already concatenated). When I implemented the OnClientMove JavaScript function, the args.get_newPath(), however, was being shown as the proper new final.

I have no idea what else I can check for this to see what's going wrong. I attached my custom FileBrowserContentProvider hoping it may help.

Thanks,
Edward

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Telerik.Web.UI.Widgets;
using System.Drawing.Imaging;
using System.Collections;
using System.IO;
using System.Drawing;
using Telerik.Web.UI;
using ICON.Management.Framework.LinqContexts;
using Icon.Common.Data;
using System.Text;
 
namespace ICON.Management.Framework.MediaLibrary
{
    public class IconFileBrowserContentProvider : FileBrowserContentProvider
    {
        #region DirectoryLister
        private class DirectoryLister
        {
            public DirectoryLister(IconFileBrowserContentProvider contentProvider, bool includeFiles, bool includeDirectories)
            {
                _contentProvider = contentProvider;
 
                _includeFiles = includeFiles;
                _includeDirectories = includeDirectories;
            }
 
 
            protected bool IsParentOf(string virtualParent, string virtualChild)
            {
                return _contentProvider.IsParentOf(virtualParent, virtualChild);
            }
 
            protected FileItem[] GetFiles(DirectoryInfo directory, PathPermissions permissions, string location)
            {
                ArrayList files = new ArrayList();
                Hashtable fileNames = new Hashtable();
                foreach (string searchPattern in _contentProvider.SearchPatterns)
                {
                    FileInfo[] fs = directory.GetFiles(searchPattern);
                    for (int i = 0; i < fs.Length; i++)
                    {
                        FileInfo file = fs[i];
                        if (!fileNames.ContainsKey(file.FullName) && _contentProvider.IsValid(file))
                        {
                            fileNames.Add(file.FullName, string.Empty);
 
                            //In list mode we need the tag because with the different folder structure
                            // we are unable to build proper urls for the files
                            string tag = IsListMode ? location + file.Name : string.Empty;
 
                            files.Add(new FileItem(file.Name, file.Extension, file.Length, string.Empty, string.Empty, tag, permissions));
                        }
                    }
                }
                return (FileItem[])files.ToArray(typeof(FileItem));
            }
 
            protected DirectoryItem[] GetDirectories(DirectoryInfo directory, string parentPath)
            {
                DirectoryInfo[] dirs = directory.GetDirectories();
                ArrayList directories = new ArrayList();
                for (int i = 0; i < dirs.Length; i++)
                {
                    DirectoryInfo dir = dirs[i];
                    if (_contentProvider.IsValid(dir))
                    {
                        directories.Add(GetDirectory(dir, VirtualPathUtility.AppendTrailingSlash(parentPath) + dir.Name));
                    }
                }
                return (DirectoryItem[])directories.ToArray(typeof(DirectoryItem));
            }
 
 
            public DirectoryItem GetDirectory(DirectoryInfo dir, string virtualName, string location, string fullPath, string tag)
            {
                PathPermissions permissions = _contentProvider.GetPermissions(fullPath);
 
                bool includeDirectories = IsListMode ? IncludeDirectories : IsParentOf(fullPath, SelectedUrl);
                bool includeFiles = IsParentOf(fullPath, SelectedUrl);
 
                DirectoryItem[] subdirectories = IncludeDirectories ? GetDirectories(dir, fullPath) : new DirectoryItem[] { };
                FileItem[] files = IncludeFiles ? GetFiles(dir, permissions, fullPath + "\\") : new FileItem[] { };
 
                DirectoryItem item = new DirectoryItem(virtualName, location, fullPath, tag, permissions, files, subdirectories);
                item.Attributes.Add("Date Created", DateTime.Now.ToString());
 
                return item;
            }
 
            public DirectoryItem GetDirectory(DirectoryInfo dir, string fullPath)
            {
                string tag = IsListMode ? fullPath : string.Empty;
                return GetDirectory(dir, dir.Name, string.Empty, fullPath, tag);
            }
 
 
            protected bool IsListMode
            {
                get
                {
                    return false;
                }
            }
 
            protected string SelectedUrl
            {
                get
                {
                    return _contentProvider.SelectedUrl;
                }
            }
 
 
            protected bool IncludeFiles
            {
                get
                {
                    return _includeFiles;
                }
            }
 
            protected bool IncludeDirectories
            {
                get
                {
                    return _includeDirectories;
                }
            }
 
            private IconFileBrowserContentProvider _contentProvider;
            private bool _includeFiles;
            private bool _includeDirectories;
        }
 
        #endregion
 
        #region DirectoryFlattener
        private class DirectoryFlattener
        {
            private ArrayList _directories = new ArrayList();
 
            public DirectoryFlattener(DirectoryItem item)
            {
                if (item == null)
                {
                    return;
                }
 
                Flatten(item);
 
                _directories.Add(item);
            }
 
            private void Flatten(DirectoryItem item)
            {
                foreach (DirectoryItem subdirectory in item.Directories)
                {
                    Flatten(subdirectory);
                }
 
                _directories.AddRange(item.Directories);
 
                item.ClearDirectories();
            }
 
            public DirectoryItem[] Directories
            {
                get
                {
                    return (DirectoryItem[])_directories.ToArray(typeof(DirectoryItem));
                }
            }
        }
 
        #endregion
 
        public IconFileBrowserContentProvider(HttpContext context, string[] searchPatterns, string[] viewPaths, string[] uploadPaths, string[] deletePaths, string selectedUrl, string selectedItemTag)
            : base(context, searchPatterns, viewPaths, uploadPaths, deletePaths, selectedUrl, selectedItemTag)
        {
            ProcessPaths(ViewPaths);
            ProcessPaths(UploadPaths);
            ProcessPaths(DeletePaths);
            SelectedUrl = RemoveProtocolNameAndServerName(GetAbsolutePath(SelectedUrl));
        }
 
 
        protected virtual bool IsValid(FileInfo file)
        {
            return true;
        }
 
        protected virtual bool IsValid(DirectoryInfo directory)
        {
            return true;
        }
 
        public override DirectoryItem ResolveRootDirectoryAsTree(string path)
        {
            string physicalPath = path;
 
            DirectoryInfo info = new DirectoryInfo(path);
 
            if (!info.Exists)
            {
                return null;
            }
 
            string virtualName = info.Name;
 
            if (UploadPaths.Contains(path)
                || ViewPaths.Contains(path)
                || DeletePaths.Contains(path))
            {
                using (IconStorageCentralContext context = DbUtils.IconStorageCentralDataContext)
                {
                    virtualName = (from libraries in context.Libraries
                                    where libraries.Id == int.Parse(info.Name)
                                     select libraries.Name).Single();
                }
            }
 
            string virtualParentPath = info.Parent.FullName;
 
            DirectoryLister directoryLister = new DirectoryLister(this, false, true);
 
            return directoryLister.GetDirectory(info, virtualName, virtualParentPath, path, string.Empty);
        }
 
 
        public override DirectoryItem ResolveDirectory(string path)
        {
            string physicalPath = path;
 
            DirectoryInfo dir = new DirectoryInfo(physicalPath);
            if (!dir.Exists)
            {
                return null;
            }
 
            DirectoryLister directoryLister = new DirectoryLister(this, true, false);
 
            return directoryLister.GetDirectory(dir, path);
        }
 
        public override bool CanCreateDirectory
        {
            get
            {
                return true;
            }
        }
 
        public override string GetFileName(string url)
        {
            return Path.GetFileName(RemoveProtocolNameAndServerName(GetAbsolutePath(url)));
        }
 
        public override string GetPath(string url)
        {
            string virtualPath = RemoveProtocolNameAndServerName(GetAbsolutePath(url));
 
            return virtualPath;
        }
 
        public override Stream GetFile(string url)
        {
            string physicalPath = url;
 
            if (!System.IO.File.Exists(physicalPath))
            {
                return null;
            }
 
            return System.IO.File.OpenRead(physicalPath);
        }
 
        public override string StoreBitmap(Bitmap bitmap, string url, ImageFormat format)
        {
            bitmap.Save(url, format);
 
            return url;
        }
 
        public override string StoreFile(UploadedFile file, string path, string name, params string[] arguments)
        {
            string targetFullPath = Path.Combine(path, name);
            if (System.IO.File.Exists(targetFullPath))
            {
                System.IO.File.Delete(targetFullPath);
            }
            //normalize slashes
            file.SaveAs(targetFullPath);
            return targetFullPath;
        }
 
        public override string DeleteFile(string path)
        {
            string physicalPath = path;
            try
            {
                if (System.IO.File.Exists(physicalPath))
                {
                    if ((System.IO.File.GetAttributes(physicalPath) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                    {
                        return "FileReadOnly";
                    }
                    System.IO.File.Delete(physicalPath);
                }
            }
            catch (UnauthorizedAccessException)
            {
                return "NoPermissionsToDeleteFile";
            }
            return string.Empty;
        }
 
        public override string DeleteDirectory(string path)
        {
            string physicalPath = path;
            try
            {
                if (Directory.Exists(physicalPath))
                {
                    Directory.Delete(physicalPath, true);
                }
            }
            catch (UnauthorizedAccessException)
            {
                return "NoPermissionsToDeleteFolder";
            }
            return string.Empty;
        }
 
        public override string CreateDirectory(string path, string name)
        {
            if (name.IndexOfAny(Path.GetInvalidPathChars()) >= 0)
            {
                return "InvalidCharactersInPath";
            }
            string newFolderPath = (path + name);
            if (Directory.Exists(newFolderPath))
            {
                return "DirectoryAlreadyExists";
            }
            try
            {
                Directory.CreateDirectory(newFolderPath);
            }
            catch (UnauthorizedAccessException)
            {
                return "NoPermissionsToCreateFolder";
            }
            catch (Exception e)
            {
                return e.Message;
            }
            return string.Empty;
        }
 
        public override string MoveDirectory(string path, string newPath)
        {
            string oldPhysicalPath = path;
            string newPhysicalPath = newPath;
            try
            {
                Directory.Move(oldPhysicalPath, newPhysicalPath);
            }
            catch (Exception e)
            {
                return e.Message;
            }
            return string.Empty;
        }
 
        public override string MoveFile(string path, string newPath)
        {
            string oldPhysicalPath = path;
            string newPhysicalPath = newPath;
            if (!System.IO.File.Exists(oldPhysicalPath))
                return "FileNotFound";
            if (System.IO.File.Exists(newPhysicalPath))
                return "NewFileAlreadyExists";
            try
            {
                System.IO.File.Move(oldPhysicalPath, newPhysicalPath);
            }
            catch (UnauthorizedAccessException)
            {
                return "NoPermissionsToMoveFile";
            }
            return string.Empty;
        }
 
        public void ProcessPaths(string[] paths)
        {
            for (int i=0; i < paths.Length; i++)
            {
                paths[i] = GetAbsolutePath(paths[i]);
            }
        }
 
 
        protected string GetAbsolutePath(string path)
        {
            if (path.StartsWith("~"))
            {
                path = VirtualPathUtility.AppendTrailingSlash(VirtualPathUtility.AppendTrailingSlash(Context.Request.ApplicationPath) + path.Substring(2));
 
                return path.Substring(0, path.Length - 1);
            }
            return path;
        }
 
 
        protected bool IsParentOf(string virtualParent, string virtualChild)
        {
            //original function did not cover all cases - e.g. parent="/test" and child="/testing" should return false
            if (virtualChild.ToLower().StartsWith(virtualParent.ToLower()))
            {
                if (virtualParent.Length == virtualChild.Length)
                {
                    return true;
                }
                else
                {
                    //if the parent ends with slash, or the child has a slash after the parent part
                    //we should be OK
                    int len = virtualParent.Length;
                    if (virtualChild[len] == '/' || virtualChild[len] == '\\' ||
                        virtualChild[len - 1] == '/' || virtualChild[len - 1] == '\\')
                        return true;
                }
            }
            return false;
        }
 
        protected PathPermissions GetPermissions(string path)
        {
            PathPermissions permissions = PathPermissions.Read;
            if (CanUpload(path))
                permissions |= PathPermissions.Upload;
            if (CanDelete(path))
                permissions |= PathPermissions.Delete;
 
            return permissions;
        }
 
        protected bool CanUpload(string path)
        {
            foreach (string uploadPath in UploadPaths)
            {
                if (IsParentOf(uploadPath, path))
                {
                    return true;
                }
            }
            return false;
        }
 
        protected bool CanDelete(string path)
        {
            foreach (string deletePath in DeletePaths)
            {
                if (IsParentOf(deletePath, path))
                {
                    return true;
                }
            }
            return false;
        }
 
         
    }
}
Dobromir
Telerik team
 answered on 20 May 2011
1 answer
107 views
Hello,

I'm trying to make sense of the RadWindow/RadWindowManager relation.  I see that there can be many RadWindowManager controls defined in one page (unlike the RadScriptManager/ScriptManager which requires one implementation).  But I also see that we can implement the RadWindow either inside of the RadWindowManager or as a standalone control.

What is the advantages of using the RadWindowManager beside being able to apply settings defined on the manager to the window?  Is it better to keep the RadWindowManager outside of the master page and define it where it is needed, or is it better to keep a global radwindowmanager, and have radwindow as a standalone control?

Thanks.
Georgi Tunev
Telerik team
 answered on 20 May 2011
2 answers
193 views
Hi,

I want to implement custom filtering in my radGrid, but I don't get it to work right now. What I'm trying to do is the following:

I have radGrid and the datasource of the grid is an objectdatasource. In the selecting event of the objectdatasource i add my filterexpression and sortexpression. In the function in my businesslogics, i have the filterexpression, sortexpression, startindex and maximumrows. The filterexpression is coming to the function properly, but i can't get it to work with my entitymodel. I've tried enableLinqExpression="True" and enableLinqExpression="False" but with both options it doesn't work.This is the code of the function:

 

 

public static IQueryable<vw_TrainingCompanyLocations> GetTrainingCompanyLocations(string filterExpression, string sortExpression, int maximumRows, int startRowIndex)
    {
      KolipeEntities db = new KolipeEntities();
  
      IQueryable<vw_TrainingCompanyLocations> data;
  
      if (!string.IsNullOrEmpty(filterExpression))
        data = db.vw_TrainingCompanyLocations.Where(filterExpression);
      else
        data = db.vw_TrainingCompanyLocations;
  
      return data;
    }
 

 Do you have any idea how to get this to work?

Tsvetina
Telerik team
 answered on 20 May 2011
1 answer
66 views
I have a number of forms that open in a modal RadWindow.  On the popup window, there are a number of other forms that can be edited individually.  When they are saved, I wanted just a standard MsgBox to appear like so:

MsgBox("Information has been updated. ", MsgBoxStyle.Information, "Information Update")

That works fine, however it does NOT open over the top (or take focus) over the RadWindow.

Also, once the user clicks ok on the msgbox, how can I also close the RadWindow?
Marin Bratanov
Telerik team
 answered on 20 May 2011
1 answer
64 views
I have a issue where I have the rad editor absolute positioned. When the editors sub windows popup (ex: Hyperlink manager) they are appearing behind the editor. If I drop the z_index down to a low number then they work fine, but that for me would cause a issue. I want to give the editor a higher z-index to make sure of no issues, since other objects can also be absolute positioned on the page and their is a risk of the number becoming higher than the editor z-index. Is there a way to change the sub windows z-index from code or javascript or even a css file to have higher z-indexes?

The same page worked great for years using the 6.5 version of the editor and I never ran into this problem with that editor. However IE 9 doesn't play nice with that version.
Rumen
Telerik team
 answered on 20 May 2011
2 answers
97 views
Hello, I'm trying to mimic RadGrid filtering. I would like to have e.g. 3 textboxes with filter button which would work exactly with the same way like RadGrid filtering. The same subset of filtering options and the same filterexpression generated. Could you advice me what is the best way to do so? I would not like to write such functionality from scratch.

Kind Regards
Marcin
Mira
Telerik team
 answered on 20 May 2011
2 answers
81 views
Hi,
   Using the latest version of your controls 2011.1.315.40 I have an issue where non of the radcontrols display there graphics when used in Internet Explorer 9 and with SSL. If I use any other browser including IE8 all works correctly.

I have attached a picture of what the RadGridView looks like when running under IE9 and SSL. All your controls do the same thing.

Is this a bug or am I missing something.

Thanks
Paul
Top achievements
Rank 1
 answered on 20 May 2011
1 answer
84 views
Dear Telerik,

I've got three questions concerning RadScheduler. Please, help me with them...

I'm using RadScheduler and show resource values as column names (default behaviour).

I see that there exist empty cells under each cell with resource value (see screen-shot, there I marked one of such cells in yellow)

1) Can I put something in these cells? For example I may need to show not only resource values but some additional attributes of the same resource. These cells would be a perfect place for them.

2) Can I format the text shown as column header (align text, show in bold...)?

3) Can I show more than one property of the same resource in the column header?

Thank you very much!

- Stepan.
Veronica
Telerik team
 answered on 20 May 2011
1 answer
37 views
below given is the server side code:

 protected void btnExcel_click(object sender, EventArgs e)
        {
            rg1.ExportSettings.ExportOnlyData = true;
            rg1.ExportSettings.IgnorePaging = true;
            rg1.ExportSettings.OpenInNewWindow = true;
            rg1.MasterTableView.ExportToExcel();

      }

Please do help me for the same .
Shinu
Top achievements
Rank 2
 answered on 20 May 2011
16 answers
300 views
So i would like to have the newsrotator to use pages, instead of news. I think i have the general idea here but I think i may have something incorrect in the fluent api. I end up getting

Must specify valid information for parsing in the string.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Must specify valid information for parsing in the string.

Source Error:


so in the page load for the rotator i set the rotators data source to use pages that are published
RadRotator1.DataSource =
                 App.WorkWith()
                     .Pages()
                     .Where(n => n.Page.Status == ContentLifecycleStatus.Live)
                     .Get()
                     .Take(this.NewsLimit)
                     .ToList()
                     .Join(App.WorkWith()
                                 .Images()
                                 .Get()
                                 .Where(i => i.Parent.Title == albumName.ToString() && i.Status == ContentLifecycleStatus.Live),
                                     item => item.Title.Value,
                                     image => image.Title.Value,
                                     (item, image) => new { NewsItem = item, NewsImage = image });

Then under data binding i use page instead of news item
Page newsItem =
                (Page)TypeDescriptor
                .GetProperties(e.Item.DataItem)["Page"]
                .GetValue(e.Item.DataItem);

Since pages has a description and not a summary I would like to use that
if (text != null) text.Text = newsItem.Description;

The target NewsPage uses typeof(NewsView), is there some sort of PageView?


as well as under the rotator when intialize controls i use Pages for the rotators datasource
this.RadRotator1.DataSource = App.WorkWith().Pages().Where(p => p.Page.Status == ContentLifecycleStatus.Live).Get().Take(this.NewsLimit).ToList().Join(
                    App.WorkWith().Images().Get().Where(i => i.Parent.Title == albumName && i.Status == ContentLifecycleStatus.Live),
                                                item => item.Title.Value,
                                                image => image.Title.Value,
                                                (item, image) => new { NewsItem = item, NewsImage = image });
Niko
Telerik team
 answered on 20 May 2011
Narrow your results
Selected tags
Tags
+? more
Top users last month
Rob
Top achievements
Rank 3
Bronze
Iron
Iron
Sergii
Top achievements
Rank 1
Iron
Iron
Dedalus
Top achievements
Rank 1
Iron
Iron
Lan
Top achievements
Rank 1
Iron
Doug
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Top users last month
Rob
Top achievements
Rank 3
Bronze
Iron
Iron
Sergii
Top achievements
Rank 1
Iron
Iron
Dedalus
Top achievements
Rank 1
Iron
Iron
Lan
Top achievements
Rank 1
Iron
Doug
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?