110,536
社区成员
发帖
与我相关
我的任务
分享
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string filename = FileUpload1.FileName;
//string extension=Path.GetExtension(filename); //获取后缀名
string file_name = filename.Substring(0, filename.LastIndexOf("."));//获取不含扩展名的文件名
string file_storage = Server.MapPath("~/File/storage/") + filename; //原文件存放的路径
FileUpload1.SaveAs(file_storage);
string file_bowze = Server.MapPath("~/File/bowze/") + file_name + ".swf"; //转换为SWF格式后存放的路径
string flash_file = Server.MapPath("~/FlashPaper2.2/FlashPrinter.exe");
Process pro = new Process();
pro.StartInfo.FileName = "cmd"; //调用CMD线程
pro.StartInfo.UseShellExecute = false;
pro.StartInfo.RedirectStandardInput = true; //注册输入指向
pro.StartInfo.RedirectStandardOutput = true; //注册输出指向
pro.StartInfo.CreateNoWindow = true; //不建新窗口,这个属性可以根据需要自己设定
pro.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; //隐藏窗口
pro.Start();
string input = string.Format("{0} {1} -o {2}", flash_file, file_storage, file_bowze); //类似于在DOS界面要输入的内容
pro.StandardInput.WriteLine(input); //将内容写到DOS ---个人是这么理解的
pro.StandardInput.WriteLine("exit");
pro.WaitForExit(600000);
string output = pro.StandardOutput.ReadToEnd(); //这句一定要加,输出转换好的SWF格式文件到指定位置 ,我一开始没加怎么都得不到文件
pro.Close(); //关掉线程
}
}
private void button2_Click(object sender, EventArgs e)
{
string flash_file = Application.StartupPath + "\\FlashPaper2.2\\FlashPrinter.exe";
string file_storage = Application.StartupPath + "\\2.doc";
string file_bowze = Application.StartupPath + "\\2.swf";
Process pro = new Process();
pro.StartInfo.FileName = "cmd"; //调用CMD线程
pro.StartInfo.UseShellExecute = false;
pro.StartInfo.RedirectStandardInput = true; //注册输入指向
pro.StartInfo.RedirectStandardOutput = true; //注册输出指向
pro.StartInfo.CreateNoWindow = true; //不建新窗口,这个属性可以根据需要自己设定
pro.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal; //隐藏窗口
try
{
pro.Start();
string input = string.Format("{0} {1} -o {2}", flash_file, file_storage, file_bowze); //类似于在DOS界面要输入的内容
pro.StandardInput.WriteLine(input); //将内容写到DOS ---个人是这么理解的
pro.StandardInput.WriteLine("exit");
pro.WaitForExit(600000);
string output = pro.StandardOutput.ReadToEnd(); //这句一定要加,输出转换好的SWF格式文件到指定位置 ,我一开始没加怎么都得不到文件
pro.Close(); //关掉线程
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
string filePath = filename;//需要转换的文件路径
string swfPath = filePath.Substring(0, filePath.LastIndexOf('.')) + ".swf";
if (!File.Exists(filePath) || File.Exists(swfPath)) { return; }
FileInfo finfo = new FileInfo(filePath);
int time = ((int)(finfo.Length / (1024 * 1204))) * 20 + 20;
Process pc = new System.Diagnostics.Process();
pc.StartInfo.FileName = "flashprinter";//需要启动的程序路径
pc.StartInfo.Arguments = string.Format("{0} -o {1}", filePath, swfPath);
pc.StartInfo.CreateNoWindow = true;
pc.StartInfo.UseShellExecute = false;
pc.StartInfo.RedirectStandardInput = false;
pc.StartInfo.RedirectStandardOutput = false;
pc.StartInfo.RedirectStandardError = true;
pc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
pc.Start();
bool res = pc.WaitForExit(time * 1000);
pc.Close();
pc.Dispose();