1、前面页加载DSOFramer
<head id="Head1" runat="server">
<script src="../Scripts/jsRequest.js" type="text/javascript"></script>
<title>无标题页</title>
<script language="javascript" type="text/javascript">
function openWord() {
var url = jsRequest("url");
setTimeout(function () { document.all.FramerControl1.Open(url, false, "Word.Document"); }, 1000);
}
function SaveDoc() {
var returnValue; // 保存页面的返回值
document.all.FramerControl1.HttpInit(); // 初始化Http引擎
// 添加相应的Post元素
document.all.FramerControl1.HttpAddPostString("11", "22");
// 添加上传文件
document.all.FramerControl1.HttpAddPostCurrFile("Filedate ", "");
// 提交上传文件
var url = jsRequest("url");
url = url.substring(7);
var Arr = url.split("/");
url = Arr[0];
url += "/Online/SaveWord.aspx";
var filePath = "?filePath=../";
for (i = 1; i < Arr.length; i++) {
filePath += Arr[i];
if (i < Arr.length - 1)
filePath += "/";
}
url += filePath;
url = "http://" + url;
//returnValue = document.all.FramerControl1.HttpPost("http://localhost:4468/MTask/Online/saveword.aspx?filePath=path");
returnValue = document.all.FramerControl1.HttpPost(url);
}
function FramerControl1_BeforeDocumentSaved() {
if (confirm("您确认要保存吗?")) {
SaveDoc();
}
}
</script>
<script language="javascript" for="FramerControl1" event="BeforeDocumentSaved">
<!--
FramerControl1_BeforeDocumentSaved()
//-->
</script>
</head>
<body οnlοad="openWord();" style="background-color:#C6D4E4">
<form id="Form1" method="post" runat="server">
<object id="FramerControl1" name = "MyOffice" style="LEFT: 0px; WIDTH: 1055px; TOP: 0px; right:0px; HEIGHT: 560px" classid="clsid:00460182-9E5E-11D5-B7C8-B8269041DD57" />
</form>
</body>
2、word文件修改后上传至服务器
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Text;
public partial class SaveWord : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
BinaryReader bReader = new BinaryReader(Request.InputStream);
string strTemp = Encoding.GetEncoding("iso-8859-1").GetString(
bReader.ReadBytes((int)bReader.BaseStream.Length), 0, (int)bReader.BaseStream.Length);
string match = "Content-Type: application/msword\r\n\r\n";
int pos = strTemp.IndexOf(match) + match.Length;
bReader.BaseStream.Seek(pos, SeekOrigin.Begin);
string filePath = Request.QueryString["filePath"].ToString();
string newFile = Server.MapPath(filePath);
FileStream newDoc = new FileStream(newFile, FileMode.Create, FileAccess.Write);
BinaryWriter bWriter = new BinaryWriter(newDoc);
bWriter.BaseStream.Seek(0, SeekOrigin.End);
while (bReader.BaseStream.Position < bReader.BaseStream.Length - 38)
bWriter.Write(bReader.ReadByte());
bReader.Close();
bWriter.Flush();
bWriter.Close();
}
}