[置顶] Ext.Net 1.x_Ext.Net_实现百度文库的效果


项目的预算需要个部分上传一个word的说明文件,供在线查看,通过两天的碰钉子,终于算是完成了,代码及过程贴出来,请大家指正。
上传文件并转换:
环境:网上下载了FlashPaper,用来转换文档成Swf
上传:

protected void UploadClick(object sender, DirectEventArgs e)
{
string tpl = "Uploaded file: {0}
Size: {1} bytes";
string gsdm = HttpUtility.UrlDecode(Request.Cookies["danwei"].Value).ToString();
string bmdm = HttpUtility.UrlDecode(Request.Cookies["bumen"].Value).ToString();
if (this.FileUploadField1.HasFile)
{
string FileExt = this.FileUploadField1.PostedFile.FileName.Substring(this.FileUploadField1.PostedFile.FileName.LastIndexOf("."));
//文件名使用单位+部门+年度
string FileName = "/BmysDoc/" + gsdm+"."+bmdm+"."+this.kjnd.Text+FileExt;
string SwfFile = "/BmysSwf/" + gsdm + "." + bmdm + "." + this.kjnd.Text + ".swf";
try
{
this.FileUploadField1.PostedFile.SaveAs(Server.MapPath(FileName));
ConvertToSWF(Server.MapPath(FileName), Server.MapPath(SwfFile));
X.Msg.Show(new MessageBoxConfig
{
Buttons = MessageBox.Button.OK,
Icon = MessageBox.Icon.INFO,
Title = "Success",
Message = string.Format(tpl, this.FileUploadField1.PostedFile.FileName, this.FileUploadField1.PostedFile.ContentLength)
});
}
catch (Exception exc)
{
X.Msg.Show(new MessageBoxConfig
{
Buttons = MessageBox.Button.OK,
Icon = MessageBox.Icon.ERROR,
Title = "Fail",
Message = exc.ToString()
});
}
}
else
{
X.Msg.Show(new MessageBoxConfig
{
Buttons = MessageBox.Button.OK,
Icon = MessageBox.Icon.ERROR,
Title = "Fail",
Message = "No file uploaded"
});
}
}
public void ConvertToSWF(string oldFile, string swfFile)

{

System.Diagnostics.Process pc = new System.Diagnostics.Process();

pc.StartInfo.FileName = @"F:\flashpaperDemo\FlashPaper2.2\FlashPrinter.exe";//安装路径 

pc.StartInfo.Arguments = string.Format("{0} -o {1}", oldFile, swfFile);

pc.StartInfo.CreateNoWindow = true;

pc.StartInfo.UseShellExecute = false;

pc.StartInfo.RedirectStandardInput = false;

pc.StartInfo.RedirectStandardOutput = false;

pc.StartInfo.RedirectStandardError = true;

pc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

pc.Start();

pc.WaitForExit();

pc.Close();

pc.Dispose();

}


这样在上传的同时就处理了转换
在线查看:

<ext:Button ID="Button4" runat="server" Text="查看文档" Icon="ArrowRefreshSmall">

<DirectEvents>

<Click OnEvent="ShowSwf"></Click>

</DirectEvents>

</ext:Button>

方法:

protected void ShowSwf(object sender, EventArgs e)

{

string gsdm = HttpUtility.UrlDecode(Request.Cookies["danwei"].Value).ToString();

string bmdm = HttpUtility.UrlDecode(Request.Cookies["bumen"].Value).ToString();

string SwfFile = "/BmysSwf/" + gsdm + "." + bmdm + "." + this.kjnd.Text + ".swf";

if (File.Exists(SwfFile) == false)

{

ResourceManager1.AddScript("window.open('ShowSwf.aspx?SwfFile="+SwfFile+"');");

}

else

X.MessageBox.Alert("提示", "该部门文档未发现!").Show();

}


ShowSwf.aspx代码:

protected void Page_Load(object sender, EventArgs e)
{
string SwfFile = Request.QueryString["SwfFile"];

System.Text.StringBuilder html = new System.Text.StringBuilder();
html.Append("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0\" width=\"" + "100%" + "\" height=\"" + "100%" + "\">");
html.Append("<param name=\"movie\" value=\"" + SwfFile + "\" />");
html.Append("</object>");
Response.Write(html.ToString());
}


尚未解决的缺点:
1、转换时窗口会出现转换过程,是一闪而过,也是觉得不爽,是不是转到cmd下去处理会好一点没有测试。
2、没有百度文库好看,待努力。
转自:http://ext.net.cn/thread-1373-1-1.html



 

你可能感兴趣的:([置顶] Ext.Net 1.x_Ext.Net_实现百度文库的效果)