windows mobile创建文本文件并用word打开
生活随笔
收集整理的這篇文章主要介紹了
windows mobile创建文本文件并用word打开
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
起初準備新建個word文檔,但mobile無法打開,最后換成txt搞定:
運用文件讀寫流創建并寫入內容:
代碼 ///?<summary>????????///?生成word文件
????????///?</summary>
????????///?<param?name="fileName">文件路徑</param>
????????///?<param?name="conCon">內容</param>
????????///?<returns>word文件路徑</returns>
????????public?static?string?CreateDocFile(string?conCon)
????????{
????????????//獲取系統路徑
????????????string?localFilePath?=?Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase)?+?@"\file";
????????????if?(!Directory.Exists(localFilePath))//如果文件夾不存在
????????????{
????????????????Directory.CreateDirectory(localFilePath);
????????????}
????????????//文件名
????????????string?filepath?=?localFilePath?+?@"\mobileofficegzap.txt";
????????????
????????????conCon?=?conCon.ToLower();
????????????//字符轉化
????????????conCon?=?htmltotxt(conCon);
????????????if?(!File.Exists(filepath))//如果文件不存在
????????????????File.Create(filepath);
????????????//創建寫入文件流
????????????StreamWriter?swr?=?new?StreamWriter(filepath,?false,?Encoding.Default);
????????????//寫入內容
????????????swr.Write(conCon.ToString());
????????????swr.Close();
????????????//返回文件路徑
????????????return?filepath;
????????}
?
?
?調用線程打開文件:
?
代碼 //生成文本文件并返回路徑????????????????????string?filepath?=?FileParse.CreateDocFile(str);
????????????????????if?(File.Exists(filepath))//如果文件存在開啟word線程打開
????????????????????{
????????????????????????FileParse.myFileOpen(filepath);
????????????????????}
????????????????????else
????????????????????{
????????????????????????MsgManager.Show("0014");
????????????????????}
?
?
myFileOpen方法: 代碼 ?///?<summary>????????///?打開文檔
????????///?</summary>
????????///?<param?name="filePathName"></param>
????????public?static?void?myFileOpen(string?filePathName)
????????{
????????????string?exe?=?"";
????????????string?open?=?"";
????????????try
????????????{
????????????????string?fileTag?=?filePathName.Substring(filePathName.LastIndexOf(".")?+?1,?filePathName.Length?-?filePathName.LastIndexOf(".")?-?1);
????????????????switch?(fileTag.ToLower())
????????????????{
????????????????????case?"doc":
????????????????????????{
????????????????????????????exe?=?"pword.exe";
????????????????????????????open?=?"-opendoc";
????????????????????????????break;
????????????????????????}
????????????????????case?"txt":
????????????????????????{
????????????????????????????exe?=?"pword.exe";
????????????????????????????open?=?"-opendoc";
????????????????????????????break;
????????????????????????}
????????????????????case?"xls":
????????????????????????{
????????????????????????????exe?=?"pxl.exe";
????????????????????????????open?=?"-opendoc";
????????????????????????????break;
????????????????????????}
????????????????????default:
????????????????????????break;
????????????????}
????????????????if?(exe?!=?"")
????????????????{
????????????????????System.Diagnostics.Process.Start(exe,?open?+?@filePathName);
????????????????}
????????????????else
????????????????{
????????????????????System.Diagnostics.Process?process?=?new?System.Diagnostics.Process();
????????????????????process.StartInfo.FileName?=?filePathName;
????????????????????process.EnableRaisingEvents?=?true;
????????????????????process.Start();
????????????????????listProcess.Add(process);
????????????????}
????????????}
????????????catch
????????????{
????????????????throw?new?MobileException.MobException("50002");
????????????}
????????}
?
轉載于:https://www.cnblogs.com/gjs85/archive/2010/04/11/1709625.html
總結
以上是生活随笔為你收集整理的windows mobile创建文本文件并用word打开的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 让人期待的Visual Studio 2
- 下一篇: 使用Platform Builder配置