Saturday, June 23, 2007 - Posts

KB-IE Operation Aborted
   1:  <html><body>
   2:  <img src="banner">
   3:  <table>
   4:  <tr><td>First Line</td></tr>
   5:  <tr><td><input type="text" name="txt1">
   6:  <script type="text/javascript" src="inc.js"></script>
   7:  <script type="text/javascript">
   8:      //call some function in inc.js
   9:  </script>
  10:  </td></tr>
  11:  </table></body></html>

我寫了一個類似上面的網頁,Include一個js,然後呼叫js裡的特定函數處理TextBox,看似OK,但以IE開啟時,卻會彈出Operation Aborted的MessageBox。網頁只顯示了上方的Banner Image,感覺上還來不及顯示表格,IE就出問題中止了。

Google了一下,找到這篇說明,狀況跟我十分類似。照著說明,將<script>移到</table>下方,問題迎刃而解。

【教訓】

不要在<td></td>間夾入<script> Block,以免發生不測。
不要在<table>....</table>的勢力範圍內夾入<script> Block或其他奇奇怪怪的東西,以免發生不測
(Update @ 2007-06-25,謝謝Steve補充)

Updated 2008-01-23 by Jeffrey
正解出現,在<div></div> <table></table>中修改上層元素的innerHTML或appendChild就會出事,請見: http://blog.darkthread.net/blogs/darkthreadtw/archive/2008/01/23/tips-ie-operatino-aborted-again.aspx

TIPS-Implement a Resumable FTP Download with .NET 2.0

最近手上的案子需要以FTP方式取回數百MB到上GB的ZIP檔案,過去我的做法會一個登入及下載的Script,作為FTP command line utility的輸入來源,再以Shell方式啟動,如以下的例子:

   1:  //產生FTP Script檔案
   2:  string ftpScriptFile = Server.MapPath("TempFolder\\ftp.script");
   3:  Process p = new Process();
   4:  StreamWriter sw = 
   5:      new StreamWriter(ftpScriptFile);
   6:  sw.WriteLine("username");
   7:  sw.WriteLine("password");
   8:  sw.WriteLine("bin");
   9:  sw.WriteLine("cd /download");
  10:  sw.WriteLine("get some.zip");
  11:  sw.WriteLine("quit");
  12:  sw.Close();
  13:  //呼叫FTP command line utility
  14:  p.StartInfo = new ProcessStartInfo("cmd.exe", 
  15:  "/c ftp -s:\"" + ftpScriptFile + "\" ftp.darkthread.net");
  16:  //不顯示FTP Cmd視窗
  17:  p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
  18:  p.Start();
  19:  p.WaitForExit();
  20:  //狡兔死 走狗烹 Script檔刪除
  21:  File.Delete(ftpScriptFile);

 這個方法不算漂亮,但是簡單耐用,也不太會出錯。

之前瞄過.NET 2.0的新功能,知道它多了支援FTP的內建物件--System.Net.FtpWebRequest,更讚的是,它居然還可以支援斷線續傳的功能,對於這次可能破GB的大檔下載來說,真是一整個酷呀!

不囉嗦! 程式範例如下:

   1:  private void test()
   2:  {
   3:      //宣告FTP連線
   4:      FtpWebRequest ftpReq = (FtpWebRequest)
   5:          WebRequest.Create("ftp://ftp.darkthread.net/download/some.zip");
   6:      //下載檔案
   7:      ftpReq.Method = WebRequestMethods.Ftp.DownloadFile;
   8:      //指定Username/Password
   9:      ftpReq.Credentials = new NetworkCredential("username", "password");
  10:      //指定BIN模式
  11:      ftpReq.UseBinary = true;
  12:      string zipFile = "c:\\temp\some.zip";
  13:      //支援續傳功能
  14:      FileInfo fi = new FileInfo(zipFile);
  15:      FileStream fs = null;
  16:      //檢測檔案是否存在
  17:      if (fi.Exists)
  18:      {
  19:          //檔案若存在,由剛才的中斷點繼續
  20:          ftpReq.ContentOffset = fi.Length;
  21:          fs = new FileStream(zipFile, FileMode.Append, FileAccess.Write);
  22:      }
  23:      else //檔案不存在時重新建立新檔案
  24:          fs = new FileStream(zipFile, FileMode.Create, FileAccess.Write);
  25:      //建立FTP連線
  26:      FtpWebResponse ftpResp = (FtpWebResponse)ftpReq.GetResponse();
  27:      //取得下載用的Stream物件
  28:      using (Stream stm = ftpResp.GetResponseStream())
  29:      {
  30:          //由於檔案龐大,以Block方式多批寫入
  31:          byte[] buff = new byte[2048];
  32:          int len = 0;
  33:          while (fs.Length < ftpResp.ContentLength)
  34:          {
  35:              //取得資料長度
  36:              len = stm.Read(buff, 0, buff.Length);
  37:              fs.Write(buff, 0, len);
  38:          }
  39:          stm.Close();
  40:   
  41:      }
  42:      fs.Flush();
  43:      fs.Close();
  44:  }

Update @ 2007-06-27
以上的程式碼在下載大型檔案時會因超過FTP Server Control Connection Timeout而發生Connection Closed Exception,詳情請看這裡

Search

Go

<June 2007>
SunMonTueWedThuFriSat
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567
 
RSS
【工商服務】


BlogLook Score and Rank

Syndication