Don't like ads? PRO users don't see any ads ;-)
Guest

File check

By: a guest on Aug 10th, 2012  |  syntax: C#  |  size: 2.24 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. private void bCheck_Click(object sender, EventArgs e)
  2.         {
  3.             foreach (int indexChecked in clbLog.CheckedIndices)
  4.             {
  5.                 int index2;
  6.                 index2 = indexChecked + 1;
  7.  
  8.                 Microsoft.Office.Interop.Excel.Application xlApp;
  9.                 Microsoft.Office.Interop.Excel.Workbook xlWorkbook;
  10.                 Microsoft.Office.Interop.Excel.Worksheet xlWorksheet;
  11.                 Microsoft.Office.Interop.Excel.Range range;
  12.  
  13.                 string str1;
  14.                 string str2;
  15.  
  16.  
  17.                 xlApp = new Microsoft.Office.Interop.Excel.Application();
  18.                 xlWorkbook = xlApp.Workbooks.Open(ofdInputFile.FileName, 0, false, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", true, false, 0, true, 1, 0);
  19.                 xlWorksheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkbook.Worksheets.get_Item(1);
  20.  
  21.                 range = xlWorksheet.UsedRange;
  22.  
  23.                 str1 = (string)(range.Cells[index2, 1] as Microsoft.Office.Interop.Excel.Range).Value2;
  24.                 str2 = (string)(range.Cells[index2, 2] as Microsoft.Office.Interop.Excel.Range).Value2;
  25.  
  26.                 System.Net.WebRequest request = System.Net.WebRequest.Create(str2);
  27.                 request.Method = "Head";
  28.  
  29.                 System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
  30.  
  31.                 string online = " ONLINE!";
  32.  
  33.                 string offline = " OFFLINE!";
  34.  
  35.                 if (response.StatusDescription == "OK")
  36.                 {
  37.                     clbLog.ForeColor = Color.Green;
  38.                     clbLog.Items.RemoveAt(indexChecked);
  39.                     clbLog.Items.Insert(indexChecked, str1 +  online);
  40.                 }
  41.  
  42.                 else
  43.                 {
  44.                     clbLog.ForeColor = Color.Red;
  45.                     clbLog.Items.RemoveAt(indexChecked);
  46.                     clbLog.Items.Insert(indexChecked, str1 + offline);
  47.                 }
  48.  
  49.                 xlWorkbook.Close(true, null, null);
  50.                 xlApp.Quit();
  51.  
  52.                 releaseObject(xlWorksheet);
  53.                 releaseObject(xlWorkbook);
  54.                 releaseObject(xlApp);
  55.             }
  56.         }