惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

B
Blog
Microsoft Security Blog
Microsoft Security Blog
Jina AI
Jina AI
博客园 - 叶小钗
J
Java Code Geeks
博客园 - 聂微东
博客园 - 司徒正美
大猫的无限游戏
大猫的无限游戏
阮一峰的网络日志
阮一峰的网络日志
V
V2EX
美团技术团队
WordPress大学
WordPress大学
M
MIT News - Artificial intelligence
雷峰网
雷峰网
酷 壳 – CoolShell
酷 壳 – CoolShell
GbyAI
GbyAI
罗磊的独立博客
T
The Blog of Author Tim Ferriss
aimingoo的专栏
aimingoo的专栏
T
Tailwind CSS Blog
The Cloudflare Blog
Stack Overflow Blog
Stack Overflow Blog
N
Netflix TechBlog - Medium
小众软件
小众软件

博客园 - 山 前

SharePoint中计算值公式函数简介 System.InvalidOperationException: 无法生成临时类(result=1)。 配置爬网能爬PDF文档. 检索 COM 类工厂中 CLSID 为 {.....} 的组件时失败,80070005 sql函数大全 JavaScript对象与数组参考大全 如何创建高性能的索引 MOSS模拟登录的新发现 动态调用webservice - 山 前 - 博客园 信息发布webpart——网页编辑器应用攻略 如何在同一任务列表中显示我的任务及我所属组的任务 ASP.NET 生成HTML静态页面实例 彻底弄懂CSS盒子模式之一 DOCTYPE用法详解 寻块心灵净土,遥祭遇难同胞 一个树控件类的实现---打造自己的树控件 通过在 Page 指令或 配置节中设置 validateRequest=false 可以禁用请求验证 Web Service学习 javascript知识
如何用fckeditor编辑器上传图片、flash、视频到moss的图片库中
山 前 · 2009-01-14 · via 博客园 - 山 前

FCKEditor编辑器是一款功能齐全,性能出色的编辑器。

FCKEditor由于其开放源码,自定义非常强大,因此应用范围非常广泛,许多著名论坛的编辑器都是基于此编辑器更改的。

MOSS中的RTF编辑器小巧精悍,但功能齐全性上略有不及,很难适应挑涤的企业用户的需求。因此,在信息发布等模块中,

通常采用其它的第三方编辑器。如果采用其它编辑器,它与MOSS的楔合度将是一个不得不考虑的问题。楔合度越高,在用户

体验,后期维护上占有比较大的优势。

这里我将讲解更改FCKEditor的上传图片等文件的方式提高楔合度的一个案例。

FCKEditor默认情况下,图片等文件是上传到服务器文件系统中的一个文件夹内的。这种设计机置在其它的项目中,可能不会有什么问题,但如果在MOSS项目中,将是一个不得不正视的问题。

第一、MOSS备份需要额外考虑该文件夹的备份。

第二、在NLB环境下,文件上传将会随机上传到NBL中的某一台前端上,这是一个非常严重的缺陷,用户访问时,可能造成文件访问不到。

因此,如果FCKEditor要应用到MOSS中,将不得不更改这种上传机置。试想,如果能够将图片等文件上传到MOSS中的图片库或文档库上,那么一切将迎刃而解了。

具体实现如下:

一、打开FCKeditor.Net_2.6.3工程。(网上可以下载,FCKEditor支持.net的源码)

二、FileWorkerBase.cs

更改FileUpload方法。增加图片压缩方法CreateThumbnail.

 代码如下:


protected void FileUpload( string resourceType, string currentFolder, bool isQuickUpload )
        
{
            HttpPostedFile oFile 
= Request.Files[ "NewFile" ];

            
string sFileName = "";

            
if ( oFile == null )
            
{
                
this.SendFileUploadResponse( 202, isQuickUpload );
                
return;
            }


            
// Map the virtual path to the local server path.
            
//string sServerDir = this.ServerMapFolder( resourceType, currentFolder, isQuickUpload );

            
// Get the uploaded file name.
            sFileName = System.IO.Path.GetFileName( oFile.FileName );
            sFileName 
= this.SanitizeFileName( sFileName );

            
string sExtension = System.IO.Path.GetExtension( oFile.FileName );
            sExtension 
= sExtension.TrimStart( '.' );

            
if ( !this.Config.TypeConfig[ resourceType ].CheckIsAllowedExtension( sExtension ) )
            
{
                
this.SendFileUploadResponse( 202, isQuickUpload );
                
return;
            }


            
if ( this.Config.CheckIsNonHtmlExtension( sExtension ) && !this.CheckNonHtmlFile( oFile ) )
            
{
                
this.SendFileUploadResponse( 202, isQuickUpload );
                
return;
            }


            
int iErrorNumber = 0;
            
//int iCounter = 0;

            
//文件上传到新闻图片库中
            string strFileUrl = string.Empty;
            
string strURL = "http://"+this.Page.Request.Url.Authority;
            SPSecurity.RunWithElevatedPrivileges(
delegate
            
{
                
//创建指定站点集
                using (SPSite site = new SPSite(strURL))
                
{
                    
//打开网站
                    using (SPWeb web = site.OpenWeb())
                    
{
                        
string strUserName = SPContext.Current.Web.CurrentUser.LoginName;
                        strUserName 
= strUserName.Substring(strUserName.LastIndexOf("\\"+ 1);

                        SPPictureLibrary plb 
= (SPPictureLibrary)web.Lists["新闻图片库"];

                        oFile.InputStream.Position 
= 0;
                        MemoryStream fStream 
= new MemoryStream();

                        
if (sExtension.ToLower().Equals("jpg"||
                            sExtension.ToLower().Equals(
"gif"||
                            sExtension.ToLower().Equals(
"jpeg"||
                            sExtension.ToLower().Equals(
"png"||
                            sExtension.ToLower().Equals(
"bmp"))
                        
{
                            
图像压缩开始
                            myThumbnail.Dispose();
                            myBitmap.Dispose();
                        }

                        
else
                        
{
                            fStream 
= (MemoryStream)oFile.InputStream;
                        }

                        fStream.Position 
= 0;
                        
int intLength = (int)fStream.Length;
                        
byte[] contents = new byte[intLength];
                        fStream.Read(contents, 
0, intLength);
                        
//fStream.Read(contents, 0, (int)fStream.Length);
                       
                        strFileUrl 
= "http://" + this.Page.Request.Url.Authority + plb.DefaultViewUrl.Substring(0, plb.DefaultViewUrl.LastIndexOf("Forms/"));
                        
                        web.AllowUnsafeUpdates 
= true;

                        sFileName 
= DateTime.Now.Year.ToString() +
                        DateTime.Now.Month.ToString() 
+
                        DateTime.Now.Day.ToString() 
+
                        DateTime.Now.Hour.ToString() 
+
                        DateTime.Now.Minute.ToString() 
+
                        DateTime.Now.Second.ToString() 
+
                        DateTime.Now.Millisecond.ToString() 
+ "." + sExtension;
                        strFileUrl 
+= sFileName;
                        SPFile spfile 
= web.Files.Add(strFileUrl, contents);
                                                
                        fStream.Dispose();
                        
                    }

                }

            }
);

            
this.SendFileUploadResponse(0true, strFileUrl, sFileName);
        }


        
/// <summary>
        
/// A better alternative to Image.GetThumbnail. Higher quality but slightly slower
        
/// </summary>
        
/// <param name="source"></param>
        
/// <param name="thumbWi"></param>
        
/// <param name="thumbHi"></param>
        
/// <returns></returns>

        public static Bitmap CreateThumbnail(Bitmap source, int thumbWi, int thumbHi, bool maintainAspect)
        
{
            
// return the source image if it's smaller than the designated thumbnail
            if (source.Width < thumbWi && source.Height < thumbHi) return source;

            System.Drawing.Bitmap ret 
= null;
            
try
            
{
                
int wi, hi;

                wi 
= thumbWi;
                hi 
= thumbHi;

                
if (maintainAspect)
                
{
                    
// maintain the aspect ratio despite the thumbnail size parameters
                    if (source.Width > source.Height)
                    
{
                        wi 
= thumbWi;
                        hi 
= (int)(source.Height * ((decimal)thumbWi / source.Width));
                    }

                    
else
                    
{
                        hi 
= thumbHi;
                        wi 
= (int)(source.Width * ((decimal)thumbHi / source.Height));
                    }

                }


                
// original code that creates lousy thumbnails
                
// System.Drawing.Image ret = source.GetThumbnailImage(wi,hi,null,IntPtr.Zero);
                ret = new Bitmap(wi, hi);
                
using (Graphics g = Graphics.FromImage(ret))
                
{
                    g.InterpolationMode 
= System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                    g.FillRectangle(Brushes.White, 
00, wi, hi);
                    g.DrawImage(source, 
00, wi, hi);
                }

            }

            
catch
            
{
                ret 
= null;
            }


            
return ret;
        }
 

3、编译,重新生成DLL。

该DLL支持将图片及其它上传文件上传到MOSS的新闻图片库中,同时会对上传的图片进行压缩处理。