0

我有一个启用了 ImageManager 的 radEditor 控件。此功能在我们拥有的上一个版本(2011 版)中运行良好,但现在使用我们拥有的版本,图像管理器不会插入所选图像。下面是我的 radEditor html 标签:

<telerik:RadEditor ID="txtRTE"
SpellCheckSettings-AllowAddCustom="false"
ToolsFile="~/SimpleRTEEditorTools.xml"
OnClientLoad="HandleRTEClientLoad"
ExternalDialogsPath="~/RadControls/EditorDialogs/"
runat="server"
Height="200"
Skin="Default"
EditModes="Design"
AllowScripts="false"
StripFormattingOptions="All">
<ImageManager ViewPaths=".." UploadPaths=".." SearchPatterns="*.jpg,*.gif,*.png" EnableImageEditor="False" ViewMode="Grid" />

我正在 page_load 方法后面的代码中编辑 ViewPaths 和 uploadPaths:

txtRTE.ImageManager.ViewPaths = paths;
txtRTE.ImageManager.UploadPaths = paths;
txtRTE.ImageManager.ContentProviderTypeName = typeof(FolderContentProvider).AssemblyQualifiedName;

我们实现了自己的内容提供程序,如下所示:

public class FolderContentProvider : FileBrowserContentProvider
    {
        private string ROOT_DIRECTORY_FULL_PATH = 
            //Path to record documents folder
            System.Configuration.ConfigurationManager.AppSettings[Constants.RECORD_DOC_ROOT_FOLDER_APP_KEY].ToString() + 
            //folder containing images
            Constants.Record_DOC_FORM_TEXT_IMAGE_FOLDER + "\\" +
            //to get Record ID
            ((MyAppPrincipal)System.Threading.Thread.CurrentPrincipal).Record.ID;

         public string RootDirectory
        {
            get
            {
                return ROOT_DIRECTORY_FULL_PATH;
            }
            private set
            {

            }
        }

        private PathPermissions fullPermissions = PathPermissions.Read | PathPermissions.Upload;

        private DirectoryItem[] GetSubDirectories(string path)
        {
            //we have only one directory no sub directories
            //no need to go to file system to find that out
            return new DirectoryItem[0];
        }

        private string GetDirectoryFullPath(string path)
        {
            return RootDirectory;
        }

        private FileItem[] GetFiles(string path)
        {
            string[] filesFullName = Directory.GetFiles(RootDirectory);
            ArrayList files = new ArrayList();
            for (int i = 0; i < filesFullName.Length; i++)
            {
                string fullPath = filesFullName[i];
                System.IO.FileInfo currentFile = new System.IO.FileInfo(fullPath);
                if (IsAlowedFileExtension(currentFile.Extension))
                {
                    string url = string.Format("{0}?path={1}", HttpContext.Current.Request.ApplicationPath + "/app/FormTextImageHandler.ashx", currentFile.Name);

                    files.Add(new FileItem(
                        currentFile.Name, //file name
                        currentFile.Extension, //extension
                        currentFile.Length, //size
                        string.Empty,//currentFile.FullName, //location
                        url, //url
                        string.Empty,//tag
                        fullPermissions//permissions
                        )); 
                }
            }
            return (FileItem[])files.ToArray(typeof(FileItem));
        }

        private bool IsAlowedFileExtension(string Extension)
        {
            if (Extension.Equals(".gif", StringComparison.InvariantCultureIgnoreCase))
                return true;
            if (Extension.Equals(".jpg", StringComparison.InvariantCultureIgnoreCase))
                return true;
            if (Extension.Equals(".png", StringComparison.InvariantCultureIgnoreCase))
                return true;
            return false;
        }

        public FolderContentProvider(HttpContext context, string[] searchPatterns, string[] viewPaths, string[] uploadPaths, string[] deletePaths, string selectedUrl, string selectedItemTag)
            : base(context, searchPatterns, viewPaths, uploadPaths, deletePaths, selectedUrl, selectedItemTag)
        {
        }

        public override string DeleteFile(string path)
        {
            //we do not allow removing files
            return null;
        }

        public override string DeleteDirectory(string path)
        {
            //we don't have any sub directories
            //and moreover we don't give delete rights
            return null;
        }

        public override string StoreFile(Telerik.Web.UI.UploadedFile file, string path, string name, params string[] arguments)
        {
            int fileLength = (int)file.InputStream.Length;
            byte[] content = new byte[fileLength];
            file.InputStream.Read(content, 0, fileLength);
            string fullPath = RootDirectory +"\\"+ name;

            FileStream fileStream = new FileStream(fullPath, FileMode.OpenOrCreate);
            fileStream.Write(content, 0, content.Length);
            fileStream.Flush();
            fileStream.Close();
            return string.Empty;
        }

        public override DirectoryItem ResolveDirectory(string path)
        {
            DirectoryItem[] directories = new DirectoryItem[0];
            FileItem[] files = this.GetFiles(RootDirectory);
            DirectoryItem dir = new DirectoryItem("Images", string.Empty, RootDirectory, string.Empty, fullPermissions, files, directories);
            return dir;
        }

        public override DirectoryItem ResolveRootDirectoryAsTree(string path)
        {
            //we don't have any subdirectories - everythinng is in the same folder
            DirectoryItem[] directories = new DirectoryItem[0];
            FileItem[] files = this.GetFiles(RootDirectory);
            DirectoryItem root = new DirectoryItem("Images", string.Empty, "Images\\", string.Empty, fullPermissions, files, directories);
            return root;
        }

        public override bool CanCreateDirectory
        {
            get
            {
                return false;
            }
        }

        public override string CreateDirectory(string path, string name)
        {
            return null;
        }

        public override string StoreBitmap(Bitmap bitmap, string url, ImageFormat format)
        {
            return null;
        }

        public override Stream GetFile(string url)
        {
            return null;
        }

        public override string GetPath(string url)
        {
            return RootDirectory;
        }

        public override string GetFileName(string url)
        {
            return null;
        }

        [Obsolete]
        public override DirectoryItem[] ResolveRootDirectoryAsList(string path)
        {
            return null;
        }

        public override bool CheckWritePermissions(string folderPath) {
            return true;
        }
    }

知道为什么旧版本能够插入该字段,但新版本不能?

4

1 回答 1

0

FileBrowserProvider API 可以在新旧版本之间更改。这就是为什么我的建议是检查以下演示的代码http://demos.telerik.com/aspnet-ajax/editor/examples/dbfilebrowsercontentprovider/defaultcs.aspx按预期工作并将其与您的自定义解决方案的代码进行比较.

如果您有任何自定义对话框,您可能需要从您正在使用的新安装中复制 EditorDialogs 文件夹并从头开始自定义它们。

最好的问候, 瘤胃

于 2014-06-19T07:52:22.827 回答