【问题标题】:RadEditor.ImageManager not inserting image on clicking InsertRadEditor.ImageManager 在单击插入时未插入图像
【发布时间】:2014-06-17 20:16:45
【问题描述】:

我有一个启用了 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;
        }
    }

知道为什么旧版本能够插入到字段中,而新版本不能?

【问题讨论】:

  • 我用 chrome 和 IE 浏览器调试工具检查了是否有任何错误,但什么也没有出现。也没有发生服务器端错误。

标签: telerik radeditor


【解决方案1】:

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

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

最好的问候, 瘤胃

【讨论】:

  • 谢谢,我会尝试使用我当前的dll,并在这个项目中替换它们,看看它是否会给我同样的问题
  • 不幸的是,提供的链接中的示例不使用自定义内容提供程序,就像我一样。还有其他想法吗?
  • 它确实使用了演示描述中所述的自定义内容提供程序:此示例演示了自定义 FileBrowserContentProvider 的实现,使用 SQL 数据库作为文件源。在离线演示安装中,DBContentProvider 类位于 App_Code\Editor\ 文件夹或此代码库中:telerik.com/support/code-library/aspnet-ajax/file-explorer/…
猜你喜欢
  • 1970-01-01
  • 2018-11-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-20
  • 2019-12-26
  • 1970-01-01
  • 2021-06-17
相关资源
最近更新 更多