点聚的weboffice控件,我把文件从服务器上读到weboffice控件上了,现在的问题的,当用户修改了文件(.doc),我怎么保存回服务器上,意思就是说,比如一份公文,我通过普通的上传,传到服务器上了,用户再处理这份公文的时候也看得到这个word,现在他修改了这份公文的内容,要把他保存到服务器上,控件自带的保存按钮只能保存在本机打开的文件,无法远程服务器的问题。有做过的人麻烦给段代码,最好加上备注,谢谢 c#.net版的。再此谢过!。
解决方案 »
- 今天看到一个日期表示方法,2011-01-21, 它存在DB里是"111L", 这是怎么转换的? 二者之间是怎么转换的呢? 请知道的高手指点下...
- 论坛里有人弹吉他吗
- 谁了解可拖曳的页面布局???
- 求思归的一篇文章
- cookie再问!不解决继续开贴加分。。。。
- 请帮我写一段下面的sql语句(Sql Server 2000)(绝对给分)
- datagrid中如何显示图片?
- form布局设计
- 请各位看看这几句话是什么意思,请帮我详细解答一下带?的是什么意思!谢谢各位了!
- 愚蠢语法问题,vb6.0中的 iif 在 C# 中应该怎样写?
- MSChart使用 饼图半透明
- Repeater 如何实现4级嵌套呢?
var webObj=document.getElementById("WebOffice1"); //根据Weboffice控件id获取对象
webObj.HttpInit(); //初始化Http引擎
// 添加相应的Post元素
webObj.HttpAddPostCurrFile("uploadFile",""); // 上传文件,这里的uploadFile指的是后台Action接收jsp页面的文件对象,属性名需要一致,我使用的是Struts 2;weboffice模拟的一个Form表单,表单元素类型为File,名称为uploadFile
returnValue = webObj.HttpPost("/请求处理的Action.action?参数名=参数值");
// 判断上传是否成功if("success" == returnValue){
alert("成功!");
}else if("failed" == returnValue){
alert("输入数据不正确!");
}
但是我用这个请求的时候,总是报告错误,而且后台也没进去。
单独把这个请求处理的Action.action?参数名=参数值在IE上运行是可以,还有什么地方要注意的?
<head runat="server">
<title></title>
</head>
<body style =" text-align :center ;">
<form id="form1" name="myform" action="#">
<%
string url = this.Session["url"].ToString();
string id, docType, docTitle;
id = Request.QueryString["id"];
if (string.IsNullOrEmpty(id))
docType = Request.Form["DocType"];
else
{
docTitle = Request.QueryString["docTitle"];
docType = Request.QueryString["docType"];
}
%>
<script language ="javascript" type ="text/javascript" for="WebOffice1" event="NotifyCtrlReady">
WebOffice1_NotifyCtrlReady();
</script>
<table>
<tr>
<td>标题</td>
<td rowspan="2">
<input name ="DocTitle" size ="14" id="txtDocTitle" />
</td>
<td rowspan="2">
<input id="File1" type="file" name ="DocFilePath" size="34"/>
</td>
<td rowspan ="2">
<div>
<input type="button" value="上传到服务器" onclick="return SaveToDb()"/>
<input type ="button" value ="返回" onclick="quit()" />
<span>服务器路径:<%=url %></span>
</div>
</td>
</tr>
</table>
<div>
<script language ="javascript" type ="text/javascript">
var s = ""
s += "<object id=WebOffice1 height=768 width='80%' style='LEFT: 0px; TOP: 0px' classid='clsid:E77E049B-23FC-4DB8-B756-60529A35FAD5' codebase='weboffice_pdf_v6.0.5.0.cab#version=6,0,5,0'>"
s += "<param name='_ExtentX' value='6350'><param name='_ExtentY' value='6350'>"
s += "</object>"
document.write(s);
</script>
</div>
<script language="javascript" type="text/javascript">
function window_onunload() {
document.all.WebOffice1.Close();
}
// -----------------------------== 修订文档 ==------------------------------------ //
function ProtectRevision() {
document.all.WebOffice1.SetTrackRevisions(1)
} // -----------------------------== 隐藏修订 ==------------------------------------ //
function UnShowRevisions() {
document.all.WebOffice1.ShowRevisions(0);
}
// --------------------------== 显示当前修订 ==---------------------------------- //
function ShowRevisions() {
document.all.WebOffice1.ShowRevisions(1);
}
// -------------------------== 接受当前所有修订 ------------------------------ //
function AcceptAllRevisions() {
document.all.WebOffice1.SetTrackRevisions(4);
}
// 保存
function SaveToDb() {
var returnValue;
if (myform.DocTitle.value == "") {
alert("文档标题不能为空");
myform.DocTitle.focus();
return false;
}
else {
document.all.WebOffice1.OptionFlag = 0x0080;
document.all.WebOffice1.HttpInit();
document.all.WebOffice1.SetTrackRevisions(0);
document.all.WebOffice1.HttpAddPostString("ID", "");
document.all.WebOffice1.HttpAddPostString("DocTitle", encodeURI(encodeURI(myform.DocTitle.value)));
document.all.WebOffice1.HttpAddPostString("DocType", "<%=docType %>");
//把当前文档添加到Post元素列表中,文件的标识符䶿DocContent
document.all.WebOffice1.HttpAddPostCurrFile("DocContent", "");
document.all.WebOffice1.HttpPost("<%=url %>/upload.aspx");
}
}
function quit() {
document.all.WebOffice1.Close();
window.location.href = "DocList.aspx";
}
function WebOffice1_NotifyCtrlReady() {
//LoadOriginalFile接口装载文件,
//如果是编辑已有文件,则文件路径传给LoadOriginalFile的第一个参数
if ('<%=id %>' == null || '<%=id %>' == "") {
document.all.WebOffice1.LoadOriginalFile("", "<%=docType %>");
}
else {
document.all.WebOffice1.LoadOriginalFile("<%=url %>/GetDoc.aspx?ID=<%=id%>", "<%=docType %>");
document.all.WebOffice1.SetTrackRevisions(1);
document.all.WebOffice1.ShowRevisions(1);
}
//屏蔽标准工具栏的前几个按钮
document.all.WebOffice1.SetToolBarButton2("Standard", 1, 1);
document.all.WebOffice1.SetToolBarButton2("Standard", 2, 1);
document.all.WebOffice1.SetToolBarButton2("Standard", 3, 1);
//屏蔽文件菜单项
document.all.WebOffice1.SetToolBarButton2("Menu Bar", 1, 1);
//屏蔽 保存快捷键(Ctrl+S)
document.all.WebOffice1.SetKeyCtrl(595, -1, 0);
//屏蔽 打印快捷键(Ctrl+P)
document.all.WebOffice1.SetKeyCtrl(592, -1, 0);
}
</script>
</form>
</body>
</html>这个是HTML,关键部分在于SaveToDb这个JS函数,获得文档的内容,然后传给服务器保存就行了!服务器代码下面会给出
{
SqlCommand cmd;
SqlConnection cn;
string docTitle, docType; protected void Page_Load(object sender, EventArgs e)
{
Response.Clear(); string id = Request.Params["DocID"];
docTitle = Request .Params["DocTitle"];
docType =Request .Params ["DocType"];
if (docType == "")
docType = "doc";
if (Request.Files.Count > 0)
{
HttpPostedFile file = Request.Files[0];
int fileLength = file.ContentLength;
byte[] photoArray = new Byte[fileLength];
Stream photoStream = file.InputStream;
photoStream.Read(photoArray, 0, fileLength); string strcn = ConfigurationManager.ConnectionStrings["WebOffice"].ConnectionString;
cn = new SqlConnection(strcn);
cn.Open(); string sql;
if (!String.IsNullOrEmpty(id))
{
sql = "update WebDoc Set DocContent=@DocContent where DocID=@ID";
cmd = new SqlCommand(sql, cn);
cmd.Parameters.Add("@ID",SqlDbType.Int).Value =id;
cmd.Parameters.Add("@DocContent", SqlDbType.Binary).Value = photoArray;
cmd.ExecuteNonQuery();
}
else
{
sql = "Insert into WebDoc(DocTitle,DocType,DocContent) values(@DocTitle,@DocType,@DocContent)";
cmd =new SqlCommand(sql,cn);
cmd.Parameters.Add("@DocTitle", SqlDbType.VarChar, 50).Value = docTitle;
cmd.Parameters.Add("@DocType", SqlDbType.VarChar, 10).Value = docType;
cmd.Parameters.Add("@DocContent", SqlDbType.Binary).Value = photoArray;
cmd.ExecuteNonQuery();
}
cn.Close();
Response.Write("succeed");
Response .End();
}
else
Response.Write("fail");
}
}希望对你有帮助!