62,072
社区成员
发帖
与我相关
我的任务
分享
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
try{
string fileName = FileUpload1.FileName;
string fileExtention = FileUpload1.FileName.Substring(fileName.LastIndexOf(".") + 1);
string filePath = HttpContext.Current.Server.MapPath("~/TestSWF\\") + fileName;
FileUpload1.SaveAs(filePath);
Page.ClientScript.RegisterStartupScript(this.GetType(),"","<script>alert('上传成功')</script>");
//切记,使用pdf2swf.exe 打开的文件名之间不能有空格,否则会失败
string cmdStr = HttpContext.Current.Server.MapPath("~/SWFTools/pdf2swf.exe");
string savePath = HttpContext.Current.Server.MapPath("~/TestSWF/");
string sourcePath=@""""+ savePath + fileName+@"""" ;
string targetPath=@""""+ savePath + fileName.Substring(0, fileName.LastIndexOf(".")) + ".swf"+@"""";
//@"""" 四个双引号得到一个双引号,如果你所存放的文件所在文件夹名有空格的话,要在文件名的路径前后加上双引号,才能够成功
// -t 源文件的路径
// -s 参数化(也就是为pdf2swf.exe 执行添加一些窗外的参数(可省略))
string argsStr = " -t " +sourcePath+ " -s flashversion=9 -o " +targetPath;
ExcutedCmd(cmdStr,argsStr);
ListBox1.Items.Add(new ListItem(fileName.Substring(0, fileName.LastIndexOf(".")) + ".swf", fileName.Substring(0, fileName.LastIndexOf(".")) + ".swf"));
}
catch
{
}
}
}
private static void ExcutedCmd(string cmd, string args)
{
using (Process p = new Process())
{
ProcessStartInfo psi = new ProcessStartInfo(cmd,args);
p.StartInfo = psi;
p.Start();
p.WaitForExit();
}
}
protected void Button2_Click1(object sender, EventArgs e)
{
Response.Redirect("~/Viewer.aspx?id="+HttpUtility.HtmlEncode(ListBox1.SelectedValue));
}