VSTO思考系列之在线升级的实现

前提:要知道vsto类项目的生命周期=文档的生命周期,当文档关闭的时候,项目也就关闭了;

方案:

项目:

resutFul服务端项目:java实现,此处省略

vsto项目:zhucheng.docx

升级项目:shengji.exe

核心代码

vsto项目核心代码,word文档启动的时候,去调用shengji.exe,并关闭word进程

 1   private void ThisDocument_Startup(object sender, System.EventArgs e)
 2         {
 3             //定义一个进程
 4             Process myProcess = new Process();
 5             string fileName = @"shengji.exe";
 6             ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(fileName);
 7             myProcess.StartInfo = myProcessStartInfo;
 8             myProcess.Start();
 9             //while (!myProcess.HasExited)
10             //{
11             //    myProcess.WaitForExit();
12             //}
13             //int returnValue = myProcess.ExitCode;
14 
15             MessageBox.Show("word开始关闭。。。");
16             Object Nothing = System.Reflection.Missing.Value; 
17             Object saveChanges = Word.WdSaveOptions.wdDoNotSaveChanges;
18             this.Application.Quit(ref saveChanges, ref Nothing, ref Nothing);
19             this.Close(ref saveChanges, ref Nothing, ref Nothing);//关闭旧doc并保存               
20         }

升级项目

抛砖引玉结束,其他大家自己完善~

 

posted @ 2014-11-25 11:06  韩慧兵  阅读(175)  评论(0编辑  收藏  举报