DSOFramer的使用(二)

來源:互聯網
上載者:User

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 onload="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();

}
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.