有没有闲着的 来个人帮忙重构下
C# codepublic string file;//显示生成完成的swf文件 protected void Button1_Click(object sender, EventArgs e) { string UploadFilePath = Server.MapPath(this.HiddenField1.Value);//保存上传的PDF或者其他可以打印的文件(DOC,DOCX等) /UploadFile/系统分析师通过的经验.doc string NewUploadFilePath = string.Empty;//转换WPS文件路径 string ext = Path.GetExtension(UploadFilePath); if ((".wps,.et,.pps,.dps,.pps").Contains(ext)) { switch (ext) { case ".wps"://wps文件 NewUploadFilePath = Path.ChangeExtension(UploadFilePath, ".doc"); File.Move(UploadFilePath, NewUploadFilePath); break; case ".et"://wps的表格文件 NewUploadFilePath = Path.ChangeExtension(UploadFilePath, ".xls"); File.Move(UploadFilePath, NewUploadFilePath); break; case ".pps": case ".dps": NewUploadFilePath = Path.ChangeExtension(UploadFilePath, ".ppt"); File.Move(UploadFilePath, NewUploadFilePath); break; } try { if (UploadFilePath != null) { string SwfFile = strType(UploadFilePath);//得到文件类型 if (SwfFile != null) { string file = NewUploadFilePath.Replace(SwfFile, ".swf"); if (!File.Exists(file)) { bool isconvert = ConvertPdfToSwf(NewUploadFilePath, file.Replace("UploadFile", "SwfFolder"));//执行转换 if (isconvert == true) { file = Path.GetFileName(file); string FlashView = "http://199.99.99.111:8011/FlashPrinter/Interface/FlashView.aspx"; Response.Write(" <script> window.location.href= '" + FlashView + "?dFile=" + HttpUtility.UrlEncode(file) + "'; </script> "); } } } } } catch (Exception) { throw; } } else { try { if (UploadFilePath != null) { string SwfFile = strType(UploadFilePath);//转换后的文件后缀名 if (SwfFile != null) { string file = UploadFilePath.Replace(SwfFile, ".swf"); if (!File.Exists(file)) { bool isconvert = ConvertPdfToSwf(UploadFilePath, file.Replace("UploadFile", "SwfFolder"));//执行转换 if (isconvert == true) { file = Path.GetFileName(file); string FlashView = "http://199.99.99.111:8011/FlashPrinter/Interface/FlashView.aspx"; Response.Write(" <script> window.location.href= '" + FlashView + "?dFile=" + HttpUtility.UrlEncode(file) + "'; </script> "); } } } } } catch (Exception) { throw; } } } /// <summary> /// 文档转swf /// </summary> /// <param name="inFilename">转换前的文件</param> /// <param name="swfFilename">转换后的文件</param> public bool ConvertPdfToSwf(string inFilename, string swfFilename) { bool isStart; Process process = new Process(); string flashPrinter = Server.MapPath("~/FlashPrinter/FlashPrinter.exe"); FileInfo fileinfo = new FileInfo(inFilename); ProcessStartInfo startInfo = new ProcessStartInfo(flashPrinter); int time = ((int)(fileinfo.Length / (1024 * 1204))) * 20 + 20; startInfo.Arguments = string.Concat(inFilename, " -o ", swfFilename); startInfo.UseShellExecute = false; startInfo.RedirectStandardInput = false; startInfo.RedirectStandardOutput = false; startInfo.RedirectStandardError = false; startInfo.CreateNoWindow = true; // 是否创建显示窗口。 startInfo.RedirectStandardError = true; startInfo.WindowStyle = ProcessWindowStyle.Hidden; process.StartInfo = startInfo; try { isStart = process.Start(); process.WaitForExit(time * 1000); process.Close(); process.Dispose(); while (!File.Exists(swfFilename)) { Thread.Sleep(1); } } catch (Exception ex) { throw ex; } finally { if (process != null) { process.Close(); } } return isStart; } /// <summary> /// 检查上传文件类型 /// </summary> /// <param name="type">文件类型</param> /// <returns></returns> public string strType(string type) { type = type.ToLower(); type = type.Substring(type.LastIndexOf(".")); if ((".swf,.flv,.doc,.docx,.jpg,.xls,.xlsx,.txt,.ppt,.pptx,.pub").Contains(type)) { return type; } else { switch (type) { //case ".txt"://txt文本文件 // type = ".rtf"; // break; case ".wps"://wps文件 type = ".doc"; break; case ".et"://wps的表格文件 type = ".xls"; break; case ".pps": case ".dps": type = ".ppt"; break; } } return type; } }