现在用DSOFramer做一个在线的office文档编辑,出现了标题描述的问题,那位有用过的,帮忙看看是什么问题
页面代码:
<object id="FramerControl1" name = "MyOffice" style="LEFT: 0px; WIDTH: 100%; TOP: 0px; HEIGHT: 100%"
classid="clsid:00460182-9E5E-11D5-B7C8-B8269041DD57" codebase="dsoframer.ocx#version=2,2,0,0" >
</object>
<input type="button" class="button" value="保存" onclick="javascript:SaveToWeb()" /><script type="text/javascript">
function SaveToWeb() {
document.all.FramerControl1.Save("c:\\1.doc", true);
document.all.FramerControl1.HttpInit();
document.all.FramerControl1.HttpAddPostString("RecordID", "无");
document.all.FramerControl1.HttpAddPostString("UserID", "无");
document.all.FramerControl1.HttpAddPostCurrFile("FileData", "mydoc.doc");
var err = document.all.FramerControl1.HttpPost("http://localhost:3071/Site/SaveDoc.aspx");
if (!err)
alert('保存失败!');
else
alert('保存成功!');
}
</script>保存文件的后台代码:
BinaryReader bReader = new BinaryReader(Request.InputStream);
string strTemp = System.Text.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 newFile = Server.MapPath(".") + "\\MyFile2.doc";
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();
页面代码:
<object id="FramerControl1" name = "MyOffice" style="LEFT: 0px; WIDTH: 100%; TOP: 0px; HEIGHT: 100%"
classid="clsid:00460182-9E5E-11D5-B7C8-B8269041DD57" codebase="dsoframer.ocx#version=2,2,0,0" >
</object>
<input type="button" class="button" value="保存" onclick="javascript:SaveToWeb()" /><script type="text/javascript">
function SaveToWeb() {
document.all.FramerControl1.Save("c:\\1.doc", true);
document.all.FramerControl1.HttpInit();
document.all.FramerControl1.HttpAddPostString("RecordID", "无");
document.all.FramerControl1.HttpAddPostString("UserID", "无");
document.all.FramerControl1.HttpAddPostCurrFile("FileData", "mydoc.doc");
var err = document.all.FramerControl1.HttpPost("http://localhost:3071/Site/SaveDoc.aspx");
if (!err)
alert('保存失败!');
else
alert('保存成功!');
}
</script>保存文件的后台代码:
BinaryReader bReader = new BinaryReader(Request.InputStream);
string strTemp = System.Text.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 newFile = Server.MapPath(".") + "\\MyFile2.doc";
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();
Visual C++ ActiveX 控件承载 Visual Basic 或 HTML 中的 Office 文档
http://support.microsoft.com/kb/311765
编辑Savedc.aspx.cs的Page_Load函数;protected void Page_Load(object sender, EventArgs e)
{
int pid = Convert.ToInt32(Request["id"]);
Byte[] source_bin = Request.BinaryRead(Request.TotalBytes);//---------------------------------------------------------------------------------------
int i, loop, again = -1, file_begin = -1;
for (i = 0; i < Request.TotalBytes; i++)
{
if (source_bin[i] == 13)
if (source_bin[i + 1] == 10)
break;
}
Byte[] MyHeader = new Byte[i];
for (loop = 0; loop < i; loop++)
MyHeader[loop] = source_bin[loop];for (i += 2; i < Request.TotalBytes; i++)
{
if (source_bin[i] == 13)
if (source_bin[i + 1] == 10)
if (source_bin[i + 2] == 13)
if (source_bin[i + 3] == 10)
break;
}file_begin = i + 4;
for (i = file_begin; i < Request.TotalBytes; i++)
{
for (loop = 0; loop < MyHeader.Length; loop++)
if (source_bin[i + loop] != MyHeader[loop])
break;
if (loop >= MyHeader.Length)
{
break;
}
}Byte[] result = new Byte[i - file_begin];
//这是个不得已的办法,用循环肯定会慢,但我不会其他方法
//希望高手完善
for (loop = file_begin; loop < i - file_begin; loop++)
result[loop - file_begin] = source_bin[loop];//---------------------------------------------------------------------------------------
//以上代码将word文档从二进制流中提取出来,存储在result[]中,方法虽笨,肯定好使
//本人不懂VB,更不懂Java,
//上面代码是我楞从梁无惧用VB写的无惧上传类V2.0里挑选有用的部分翻译成C#的,泪ing……
//看看人家梁兄,多无私,给同行提供这么好的东东
//我在网上找了N + 1天,就TM没找到C#版的,再泪ing……
//现在提供给大家,希望我是最后一个为此郁闷的人
SqlConnection myConnection = new SqlConnection("Data Source=\"localhost\";Initial Catalog=\"demo\";Persist Security Info=True;User ID=demo;Password=demo");//数据库的相关设置自己改吧
SqlCommand mycommand = myConnection.CreateCommand();
mycommand.CommandText = "UPDATE Table_word SET filedata = @myfiledata , b_finished = 1 WHERE (ID = @myID)";
mycommand.Parameters.Add("@myfiledata", SqlDbType.VarBinary, 0, "filedata");
mycommand.Parameters.Add("@myID", SqlDbType.Int, 4, "ID");SqlDataAdapter mydpt;
DataSet myds = new DataSet();mydpt = new SqlDataAdapter("SELECT ID ,filedata , b_finished FROM Table_copy WHERE (ID = " + Request["id"] + ")", myConnection);
myConnection.Open();mydpt.UpdateCommand = mycommand;
mydpt.Fill(myds);
DataTable mydt = myds.Tables[0];
DataRow myrow;
myrow = mydt.Rows[0];
myrow.BeginEdit();
myrow["filedata"] = result;
myrow.EndEdit();mydpt.Update(myds);
myConnection.Close();/**/
}
string strTemp = System.Text.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 newFile = Server.MapPath(".") + "\\MyFile2.doc";
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();可以用啊,也是只用于word2003,而word2007不行