sharepoint 2010 扩展富文本框上传图片功能extend InputFormTextBox for uploading image
2013-04-12 15:17
525 查看
在sharepoint开发中,我们有时候会用到一个叫富文本框的控件InputFormTextBox,这个控件非常好用,只是有一个地方不太人性化,就是插入上传图片的时候,只能是插入一个图片地址,而没有选择本地图片的功能。我们看看原来的界面时什么样的。
首先,在页面或者是webpart上面,添加一个富文本框InputFormTextBox的控件
<SharePoint:InputFormTextBoxTitle=""
ID="txtContents"
runat="server"TextMode="MultiLine"
Rows="15"RichText="true"
AllowHyperlink="true"
RichTextMode="FullHtml"
Width="98%"
/>
运行后的效果如下图,并点击一下插入图片的小按钮
这个时候会show出一个插入图片的页面。
发现不能直接使用上传本地图片的操作,只能插入一个服务器图片链接,很明显做得不够人性化。
这次主要是扩展下这个页面,扩展成可以添加浏览本地图片的功能,如下图:
下面是这个功能的具体做法。
在做这个功能之前,首先需要在网站上面创建一个图片库列表(图片资源)
富文本框页面代码:
<asp:ContentID="Main"
ContentPlaceHolderID="PlaceHolderMain"
runat="server">
<script>
function RTE_ModalDialog(
strBaseElementID,
strDialogName,
width,
height,
dialogArg) {
ULSopi: ;
var variables = RTE_GetEditorInstanceVariables(strBaseElementID);
if (strDialogName ==
"InsertImage") {
return showModalDialog(
variables.aSettings.urlWebRoot +
"/_layouts/SharePointProject1/ApplicationPage2.aspx?IsDlg=1&Dialog=" + strDialogName +"&LCID=" + RTE_GetWebLocale(strBaseElementID) +"&IsDlg=1",
dialogArg,
"resizable: no; status: no; help: no; " +"scroll:no;center: yes; dialogWidth:" + width +"px; " +
"dialogHeight:" + height +"px;");
}
else {
return showModalDialog(
variables.aSettings.urlWebRoot +
"/_layouts/RteDialog.aspx?Dialog=" + strDialogName +
"&LCID=" + RTE_GetWebLocale(strBaseElementID),
dialogArg,
"resizable: yes; status: no; help: no; " +"center: yes; dialogWidth:" + width +
"px; " + "dialogHeight:" + height +
"px;");
}
}
</script>
<SharePoint:InputFormTextBoxTitle=""
ID="txtContents"
runat="server"TextMode="MultiLine"
Rows="15"RichText="true"
AllowHyperlink="true"
RichTextMode="FullHtml"
Width="98%"
/>
</asp:Content>
弹出页面代码:
<asp:ContentID="PageHead"
ContentPlaceHolderID="PlaceHolderAdditionalPageHead"runat="server">
<basetarget="_self">
</asp:Content>
<asp:ContentID="Main"
ContentPlaceHolderID="PlaceHolderMain"
runat="server">
function ReturnPageValue(imgurl, des)
{
var array = new Array();
array[0] = imgurl;
array[1] = des;
window.returnValue = array;
window.close();
}
<styletype="text/css">
.TdNowrap
{
white-space:
nowrap;
vertical-align:
top;
}
</style>
<divstyle="">
<tablestyle="margin: auto;width:
250px;">
<trclass="TdNowrap">
<td>
请选择你要上传的图片
</td>
</tr>
<tr>
<tdclass="TdNowrap">
文字描述:<inputid="txtDes"
type="text"
runat="server"/>
</td>
</tr>
<tr>
<tdclass="TdNowrap">
<asp:FileUploadID="flUpload"
runat="server"
/>
</td>
</tr>
<tr>
<tdclass="TdNowrap"
align="center">
<asp:ButtonID="BtnSubmit"
runat="server"
Text="提交"OnClick="btnSave_Click"/>
<inputid="BtnClose"
type="button"
value="关闭"onclick="window.close();"/>
</td>
</tr>
</table>
</div>
</asp:Content>
弹出窗口后台代码:
protected
void btnSave_Click(object sender,
EventArgs e)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
byte[] imageData =null;
if ((flUpload.PostedFile !=null) && (flUpload.PostedFile.ContentLength > 0))
{
Stream MyStream = flUpload.PostedFile.InputStream;
long iLength = MyStream.Length;
imageData = newbyte[(int)MyStream.Length];
MyStream.Read(imageData, 0, (int)MyStream.Length);
MyStream.Close();
string filename = System.IO.Path.GetFileName(flUpload.PostedFile.FileName);
SPWeb web =SPContext.Current.Web;
SPPictureLibrary pic = (SPPictureLibrary)web.Lists["图片资源"];
SPFile archivoSubir = pic.RootFolder.Files.Add(filename, imageData);
string imageurl = archivoSubir.ServerRelativeUrl;
web.Dispose();
ClientScript.RegisterStartupScript(ClientScript.GetType(),"myscript",
"<script>ReturnPageValue('" + imageurl +"');</script>");
}
});
}
这个功能最关键的地方,就是重写了一个js的方法:RTE_ModalDialog
首先,在页面或者是webpart上面,添加一个富文本框InputFormTextBox的控件
<SharePoint:InputFormTextBoxTitle=""
ID="txtContents"
runat="server"TextMode="MultiLine"
Rows="15"RichText="true"
AllowHyperlink="true"
RichTextMode="FullHtml"
Width="98%"
/>
运行后的效果如下图,并点击一下插入图片的小按钮
这个时候会show出一个插入图片的页面。
发现不能直接使用上传本地图片的操作,只能插入一个服务器图片链接,很明显做得不够人性化。
这次主要是扩展下这个页面,扩展成可以添加浏览本地图片的功能,如下图:
下面是这个功能的具体做法。
在做这个功能之前,首先需要在网站上面创建一个图片库列表(图片资源)
富文本框页面代码:
<asp:ContentID="Main"
ContentPlaceHolderID="PlaceHolderMain"
runat="server">
<script>
function RTE_ModalDialog(
strBaseElementID,
strDialogName,
width,
height,
dialogArg) {
ULSopi: ;
var variables = RTE_GetEditorInstanceVariables(strBaseElementID);
if (strDialogName ==
"InsertImage") {
return showModalDialog(
variables.aSettings.urlWebRoot +
"/_layouts/SharePointProject1/ApplicationPage2.aspx?IsDlg=1&Dialog=" + strDialogName +"&LCID=" + RTE_GetWebLocale(strBaseElementID) +"&IsDlg=1",
dialogArg,
"resizable: no; status: no; help: no; " +"scroll:no;center: yes; dialogWidth:" + width +"px; " +
"dialogHeight:" + height +"px;");
}
else {
return showModalDialog(
variables.aSettings.urlWebRoot +
"/_layouts/RteDialog.aspx?Dialog=" + strDialogName +
"&LCID=" + RTE_GetWebLocale(strBaseElementID),
dialogArg,
"resizable: yes; status: no; help: no; " +"center: yes; dialogWidth:" + width +
"px; " + "dialogHeight:" + height +
"px;");
}
}
</script>
<SharePoint:InputFormTextBoxTitle=""
ID="txtContents"
runat="server"TextMode="MultiLine"
Rows="15"RichText="true"
AllowHyperlink="true"
RichTextMode="FullHtml"
Width="98%"
/>
</asp:Content>
弹出页面代码:
<asp:ContentID="PageHead"
ContentPlaceHolderID="PlaceHolderAdditionalPageHead"runat="server">
<basetarget="_self">
</asp:Content>
<asp:ContentID="Main"
ContentPlaceHolderID="PlaceHolderMain"
runat="server">
function ReturnPageValue(imgurl, des)
{
var array = new Array();
array[0] = imgurl;
array[1] = des;
window.returnValue = array;
window.close();
}
<styletype="text/css">
.TdNowrap
{
white-space:
nowrap;
vertical-align:
top;
}
</style>
<divstyle="">
<tablestyle="margin: auto;width:
250px;">
<trclass="TdNowrap">
<td>
请选择你要上传的图片
</td>
</tr>
<tr>
<tdclass="TdNowrap">
文字描述:<inputid="txtDes"
type="text"
runat="server"/>
</td>
</tr>
<tr>
<tdclass="TdNowrap">
<asp:FileUploadID="flUpload"
runat="server"
/>
</td>
</tr>
<tr>
<tdclass="TdNowrap"
align="center">
<asp:ButtonID="BtnSubmit"
runat="server"
Text="提交"OnClick="btnSave_Click"/>
<inputid="BtnClose"
type="button"
value="关闭"onclick="window.close();"/>
</td>
</tr>
</table>
</div>
</asp:Content>
弹出窗口后台代码:
protected
void btnSave_Click(object sender,
EventArgs e)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
byte[] imageData =null;
if ((flUpload.PostedFile !=null) && (flUpload.PostedFile.ContentLength > 0))
{
Stream MyStream = flUpload.PostedFile.InputStream;
long iLength = MyStream.Length;
imageData = newbyte[(int)MyStream.Length];
MyStream.Read(imageData, 0, (int)MyStream.Length);
MyStream.Close();
string filename = System.IO.Path.GetFileName(flUpload.PostedFile.FileName);
SPWeb web =SPContext.Current.Web;
SPPictureLibrary pic = (SPPictureLibrary)web.Lists["图片资源"];
SPFile archivoSubir = pic.RootFolder.Files.Add(filename, imageData);
string imageurl = archivoSubir.ServerRelativeUrl;
web.Dispose();
ClientScript.RegisterStartupScript(ClientScript.GetType(),"myscript",
"<script>ReturnPageValue('" + imageurl +"');</script>");
}
});
}
这个功能最关键的地方,就是重写了一个js的方法:RTE_ModalDialog
相关文章推荐
- sharepoint 2010 扩展富文本框上传图片功能extend InputFormTextBox for uploading image
- 用jsp实现简单的图片上传功能(multipart/form-data形式的表单)
- sharepoint 2010 扩展调查字段属性(6)-增加图片支持-多选-根据权限控制是否允许用户多次评选
- 如何用input标签和jquery实现多图片的上传和回显功能
- sharepoint 2010 扩展调查字段属性(1)-增加图片支持
- js拖拽图片/input上传+form提交+ajax上传到struts
- 前端form表单上传文件报No result defined for action xxx and result input
- Firemonkey扩展增强:Android 浏览器支持Input file标签上传功能
- 扩展FCKeditor编辑器的图片上传功能
- kindeditor扩展粘贴截图功能&修改图片上传路径并通过webapi上传图片到图片服务器
- <input type="image">图片按钮具有提交功能
- 分离与继承的思想实现图片上传后的预览功能:ImageUploadView
- JS,jQuery轻松实现input图片上传预览功能
- SharePoint简介WebPart入门应用一:扩展SharePoint 2007中图片展示功能
- 自定义服务器控件之:带验证功能文本框控件 TextBox (Only For IE)
- 扩展fckeditor的上传图片和上传文件功能! (二)
- 分离与继承的思想实现图片上传后的预览功能:ImageUploadView
- Bootstrap中的fileinput 多图片上传及编辑功能
- sharepoint 2010 社区中心系统-在线问答-扩展讨论板Dicussion答复功能
- FCKeditor是使用非常广泛的HTML编辑器,本文从 ASP.NET 的使用场景对 FCKeditor 与 FCKeditor.NET 的配置、功能扩展(如自定义文件上传子目录、自定义文件名、上传图片的后期处理等)、以及安全性进行初步的阐述。