公文套红方法,平时都很少用,只是在做公文处理的时候用到了,今天贴出来备用。...

公文套红方法,平时都很少用,只是在做公文处理的时候用到了,今天贴出来备用。
     // 套红处理事件
     public   void  lkbtnTaoHong_Click( object  sender, EventArgs e)
    
{
        
try
        
{
            
//模板文件
            object strTempFile = Server.MapPath("TemplateFiles/" + hidSelectedTemplateFile.Value);          
            
if (!System.IO.File.Exists(strTempFile.ToString()))
            
{
                ShowMessage(
"Notfind" ,"alert('该模板文件已不存在。');");
                
return;
            }


            FileSystemRemoting.InitFileSystemRemoting();                      
            FileClass oFileClass 
= new FileClass();
            IFile oArchBodyFile 
= oFileClass.Identify(hidBodyFileID.Value);

            
//公文正文文件
            string strBodyFile = Server.MapPath("Temporary/" + Guid.NewGuid().ToString() + Path.GetExtension(oArchBodyFile.Name));
             
//套红后的文件
            object strFullFile = Server.MapPath("Temporary/" + Guid.NewGuid().ToString() + Path.GetExtension(oArchBodyFile.Name));

            
byte[] oFileBytes = oArchBodyFile.OpenBinaryAsByte();
            FileStream oBodyFileStream 
= new FileStream(strBodyFile ,FileMode.OpenOrCreate);
            oBodyFileStream.Write(oFileBytes, 
0 , oFileBytes.Length);
            oBodyFileStream.Close();
            oBodyFileStream.Dispose();

            
//将公文正文插入模板中
            Wisesoft.Office.Word2007 fullArchWord = new Wisesoft.Office.Word2007(strTempFile, false);
            
object body = "Body";
            
if (fullArchWord.ExistBookmark(body))
            
{
                fullArchWord.InsertFileInBookmark(body, strBodyFile);
            }

            fullArchWord.Save(strFullFile);
            fullArchWord.Close();

            
//得到套红后的文档流
            FileStream oFullFileStream = new FileStream(strFullFile.ToString(), FileMode.OpenOrCreate);
            
//将套红后的公文存入文档系统
            
//TcpChannel chan=null;
            IFile oFile = null;
            ArchivesInfo archInfo 
= new Archives().GetModel(hidArchivesID.Value);            
            UserClass oUserClass 
= new UserClass();
            IUser oUser 
= oUserClass.Identify(myAccountInfo.ModelSysUser.SysuserName);            

            IOrigin oIOrigin 
= OriginClass.Identify("ArchivesManager");
            oFile 
= oFileClass.Create(oUser, OriginClass.ORIGIN_PERSONAL_DOCUMENT);
            oFile.TimeCreated 
= DateTime.Now;
            oFile.TimeLastModified 
= DateTime.Now;
            oFile.ReportDate 
= DateTime.Now;
            oFile.Name 
= Path.GetFileName(strFullFile.ToString()) ;
            oFile.Title 
= archInfo.Title;
            oFile.Author 
= oUser.Name;
            oFile.Owner 
= (Visitor)oUser;
            oFile.Store();
            oFile.SaveBinary(oFullFileStream);

            hidFullBodyFileID.Value 
= oFile.ID;
            oFullFileStream.Close();
            System.IO.File.Delete(strFullFile.ToString());
            System.IO.File.Delete(strBodyFile);
            FileSystemControl1.FileID 
= oFile.ID;
            
            
string hidFileUrl = oFile.OpenFile(FileSystemWebUIHelper.GetSystemUser(), Request.UserHostAddress);

            HtmlFileClass oHtmlFileClass 
= new HtmlFileClass();
            IHtmlFile oHtmlFile 
= oHtmlFileClass.Identify(hidFullBodyFileID.Value);
            
double iTemp = 0;
            
while (oHtmlFile == null || String.IsNullOrEmpty(oHtmlFile.Url) && iTemp < 50000)
            
{
                oHtmlFile 
= oHtmlFileClass.Identify(hidFullBodyFileID.Value);
                iTemp
++;
            }

            hidFileHTMLUrl.Value 
= oHtmlFile.Url;

            
//FileSystemWebUIHelper.ExecuteClientScript("openEditWordFile('" + hidFileUrl + "')", this.Page);            
            ShowMessage("TaoHongSuccess""alert('套红成功');SetFileUrl('" + oHtmlFile.Url + "');");
            FileSystemControl1.EditFile();

        }

        
catch (Exception exp)
        
{
            ShowMessage(
"TaoHongFailed" ,"alert('套红失败。" + exp.Message + "');");
        }

    }

转载于:https://www.cnblogs.com/wcp066/archive/2007/12/11/991215.html

你可能感兴趣的:(公文套红方法,平时都很少用,只是在做公文处理的时候用到了,今天贴出来备用。...)