Ext.Net 1.x_Ext.Net_實現百度文庫的效果

來源:互聯網
上載者:User

項目的預算需要個部分上傳一個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+"');");}elseX.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

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.