保存在线word编辑的内容到服务器

1.保存的页面的前台添加以下代码
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR"/>
<meta content="C#" name="CODE_LANGUAGE"/>
<meta content="JavaScript" name="vs_defaultClientScript"/>
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema"/>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>
</head>
<body>
<form id="Form2" method="post" runat="server" encType="multipart/form-data">
<input type=text name="RecordID" value=<%=Request.QueryString["RecordID"]%>>
</form>

</body>

2.后台相关的处理代码

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;


namespace OnlineWord
{
    public partial class SaveDoc : System.Web.UI.Page
    {
        readonly int enterCount = 12;
        string[] requestValues = new string[3];
        protected void Page_Load(object sender, System.EventArgs e)
        {


            string newFile = Server.MapPath("~/1236.doc");


            BinaryReader br = new BinaryReader(Request.InputStream);


            br.BaseStream.Seek(0, SeekOrigin.Begin);


            int enterNo = 0;
            int streamHeadLen = 0;
            while (br.BaseStream.Position < br.BaseStream.Length)
            {
                streamHeadLen++;
                char c = (char)br.ReadByte();
                if (enterNo < enterCount)
                {
                    if (c == '\n')
                    {
                        enterNo++;
                    }
                }
                else
                {
                    break;
                }
            }
            br.BaseStream.Seek(0, SeekOrigin.Begin);
            string strTemp = System.Text.UTF8Encoding.Default.GetString(br.ReadBytes(streamHeadLen - 1));


            string str = "";
            int index = 0;
            string[] requestStrings = { "RecordID", "UserID" };
            for (int i = 0; i < requestStrings.Length; i++)
            {
                str = "Content-Disposition: form-data; name=\"" + requestStrings[i] + "\"\r\n\r\n";
                index = strTemp.IndexOf(str) + str.Length;
                if (index != str.Length - 1)
                {
                    for (int j = index; j < strTemp.Length; j++)
                    {
                        if (strTemp[j] != '\r')
                            this.requestValues[i] += strTemp[j];
                        else
                            break;
                    }
                }
            }
            str = "; filename=\"";
            index = strTemp.IndexOf(str) + str.Length;
            if (index != str.Length - 1)
            {
                for (int j = index; j < strTemp.Length; j++)
                {
                    if (strTemp[j] != '\r')
                        this.requestValues[2] += strTemp[j];
                    else
                        break;
                }
            }


            FileStream newDoc = new FileStream(newFile, FileMode.Create, FileAccess.Write);
            BinaryWriter bw = new BinaryWriter(newDoc);
            bw.BaseStream.Seek(0, SeekOrigin.End);
            while (br.BaseStream.Position < br.BaseStream.Length - 38)
            {
                bw.Write(br.ReadByte());
            }
            br.Close();
            bw.Flush();
            bw.Close();


        }
        #region Web 窗体设计器生成的代码
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。            
            //            
            InitializeComponent();
            base.OnInit(e);
        }
        ///
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改        
        /// 此方法的内容。        
        ///
        private void InitializeComponent()
        {
        }
        #endregion
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值