首页 新闻 赞助 找找看

流文件的读写过程

0
悬赏园豆:10 [已解决问题] 解决于 2015-10-13 21:45

读取流文件并写入指定的文件:

  private void toolStripButtonSave_Click(object sender, EventArgs e)
        {
            if (System.IO.File.Exists(Common.UserPublic.TempFile))
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.RestoreDirectory = true;
                sfd.Filter = "*.disclosure|*.disclosure";
                sfd.InitialDirectory = System.Windows.Forms.Application.StartupPath + "//Document//";
                sfd.FileName = Common.UserPublic.NodeValue + ".disclosure";
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    this.axFramerControlMain.Close();
                    if (GetDisclosure(sfd.FileName))
                    {
                        MessageBox.Show("生成成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
        }

  private bool GetDisclosure(string file=null)
        {
            try
            {
                using (System.IO.FileStream fsRead = new System.IO.FileStream(Common.UserPublic.TempFile, System.IO.FileMode.Open))
                {
                    int fsLen = (int)fsRead.Length;
                    byte[] heByte = new byte[fsLen];
                    using (System.IO.FileStream fsWrite = new System.IO.FileStream(file, System.IO.FileMode.Append))
                    {
                        fsWrite.Write(heByte, 0, heByte.Length);
                    };
                } return true;
            }
            catch
            {
                return false;
            }
        }

从刚才写入的文件中再读取回来:

 private void toolStripButtonOpen_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "*.disclosure|*.disclosure";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                if (OpenDisclosure(ofd.FileName))
                {
                    this.BeginInvoke(new MethodInvoker(delegate()
                    {
                        OpenMaking();
                    }));
                }
            }
        }

private bool OpenDisclosure(string file = null)
        {
            Common.UserPublic.TempFile = Application.StartupPath + "\\Temp\\" + "PC-1" + ".docx";
            Common.UserPublic.RtfFile = Application.StartupPath + "\\Infroduce\\" + "PC-1" + ".rtf";
            try
            {
                using (System.IO.FileStream fsRead = new System.IO.FileStream(file, System.IO.FileMode.Open))
                {
                    int fsLen = (int)fsRead.Length;
                    //byte[] heByte = System.Text.Encoding.Unicode.GetBytes(fsRead.);
                    byte[] heByte = new byte[fsLen];
                    using (System.IO.FileStream fsWrite = new System.IO.FileStream(Common.UserPublic.TempFile, System.IO.FileMode.Append))
                    {
                        fsWrite.Write(heByte, 0, heByte.Length);
                    };
                } return true;
            }
            catch
            {
                return false;
            }
        }


  public void OpenMaking()
        {
            this.axFramerControlMain.Dispose();
            this.richTextBoxIntroduce.LoadFile(Common.UserPublic.RtfFile);
            Thread.Sleep(200);
            this.axFramerControlMain.Open(Common.UserPublic.TempFile);

            Microsoft.Office.Interop.Word.Document doc = (Microsoft.Office.Interop.Word.Document)this.axFramerControlMain.ActiveDocument;
            doc.Application.WindowSelectionChange += new Microsoft.Office.Interop.Word.ApplicationEvents4_WindowSelectionChangeEventHandler(this.SelectEvent);
        }

到OpenMaking()里面的

this.axFramerControlMain.Open(Common.UserPublic.TempFile);就报错了

我用word打开文件的时候也不行,也就是说在之前转换的时候出错了,我应该怎么设置word文件转换成流文件的格式呢?
C#
_Vegetables的主页 _Vegetables | 小虾三级 | 园豆:586
提问于:2015-10-13 17:55
< >
分享
最佳答案
0

楼主怎么解决的呢?

收获园豆:10
鱼兔兔 | 菜鸟二级 |园豆:212 | 2015-10-13 21:43

你猜

_Vegetables | 园豆:586 (小虾三级) | 2015-10-13 21:44
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册