CRM4.0读取附件文本文件

 
  string sql = "select top 1 Documentbody from Annotation where ObjectId like '%" + thePrintTempalteGuid.ToString() + "%' and MimeType like '%htm%' order by CreatedOn desc";
                    DataTable theAnnotation = new BaseSql().ExecuteReturnDataTable(sql);
                    if (theAnnotation.Rows.Count < 1)
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "nofile", "<script>alert('没有在打印模板中找到指定的模板,请将模板文件以附件形式上传到打印模板!');top.close();</script>");
                        return;
                    }
                    byte[] theHtmlFile = Convert.FromBase64String(theAnnotation.Rows[0]["DocumentBody"].ToString());
                    MemoryStream stream = new MemoryStream(theHtmlFile, 0, theHtmlFile.Length);
                    //从内存流里面将文件内容读出来
                    StreamReader reader = new StreamReader(stream, System.Text.Encoding.Default);
                    string theFileContext = reader.ReadToEnd();

posted on 2011-04-13 17:02  HelloHongfu  阅读(346)  评论(0编辑  收藏  举报

导航