成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

C# Web Services升級程序

開發 后端
本文介紹一種用C# Web Services升級程序。通過C# Web Services升級程序就象讀寫本機文件一樣簡單。所以我就直接給出代碼。

面介紹一種用C# Web Services升級程序。通過C# Web Services升級程序就象讀寫本機文件一樣簡單。所以我就直接給出代碼。

C# Web Services升級程序部分代碼:

  1. using System;  
  2. using System.Web;  
  3. using System.Web.Services;  
  4. using System.Web.Services.Protocols;  
  5. using System.IO;  
  6.  
  7. [WebService(Namespace = "http://tempuri.org/")]  
  8. [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]  
  9. public class Service : System.Web.Services.WebService  
  10. {  
  11. public Service()  
  12. {  
  13. //如果使用設計的組件,請取消注釋以下行  
  14. //InitializeComponent();  
  15. }  
  16. /// <summary> 
  17. /// 需要升級文件的服務器路徑  
  18. /// summary> 
  19. private const string UpdateServerPath ="d:\\Debug";  
  20. [WebMethod(Description = "返回服務器上程序的版本號")]  
  21. public string ServerVer()  
  22. {  
  23. return "4.0";  
  24. }  
  25. [WebMethod(Description = "返回需更新的文件")]  
  26. public string[] NewFiles()  
  27. {  
  28. DirectoryInfo di = new DirectoryInfo(UpdateServerPath);  
  29. FileInfo[] fi = di.GetFiles();  
  30. int intFilesfi.Length;  
  31. string[] myNewFiles = new string[intFiles];  
  32. int i = 0;  
  33. foreach (FileInfo fiTemp in fi)  
  34. {  
  35. myNewFiles[i] = fiTemp.Name;  
  36. System.Diagnostics.Debug.WriteLine(fiTemp.Name);  
  37. i++;  
  38. }  
  39.  
  40. return myNewFiles;  
  41. }  
  42. [WebMethod(Description = "返回需更新的文件的大小")]  
  43. public int AllFileSize()  
  44. {  
  45. int filesize = 0;  
  46. string[] files = Directory.GetFiles(UpdateServerPath);  
  47. foreach (string file in files)  
  48. {  
  49. FileInfo myInfo = new FileInfo(file);  
  50. filesize += (int)myInfo.Length / 1024;  
  51. }  
  52. return filesize;  
  53. }  
  54.  
  55. [WebMethod(Description = "返回給定文件的字節數組")]  
  56. public byte[] GetNewFile(string requestFileName)  
  57. {  
  58. ///得到服務器端的一個文件  
  59. if (requestFileName != null || requestFileName != "")  
  60. return getBinaryFile(UpdateServerPath + "\\"+requestFileName);  
  61. else  
  62. return null;  
  63. }  
  64.  
  65. /// <summary> 
  66. /// 返回所給文件路徑的字節數組。  
  67. /// summary> 
  68. /// <param name="filename">param> 
  69. /// <returns>returns> 
  70. private byte[] getBinaryFile(string filename)  
  71. {  
  72. if (File.Exists(filename))  
  73. {  
  74. try  
  75. {  
  76. //打開現有文件以進行讀取。  
  77. FileStream s = File.OpenRead(filename);  
  78. return ConvertStreamToByteBuffer(s);  
  79. }  
  80. catch  
  81. {  
  82. return new byte[0];  
  83. }  
  84. }  
  85. else  
  86. {  
  87. return new byte[0];  
  88. }  
  89. }  
  90. /// <summary> 
  91. /// 把給定的文件流轉換為二進制字節數組。  
  92. /// summary> 
  93. /// <param name="theStream">param> 
  94. /// <returns>returns> 
  95. private byte[] ConvertStreamToByteBuffer(System.IO.Stream theStream)  
  96. {  
  97. int b1;  
  98. System.IO.MemoryStream tempStream = new System.IO.MemoryStream();  
  99. while ((b1 = theStream.ReadByte()) != -1)  
  100. {  
  101. tempStream.WriteByte(((byte)b1));  
  102. }  
  103. return tempStream.ToArray();  
  104. }  
  105.  

【編輯推薦】

  1. 定義C#接口學習經驗
  2. C# ListBox學習筆記
  3. 操作C# Dataset介紹
  4. C# ODBC訪問MySQL數據庫
  5. 淺析C#和Java不同點
責任編輯:佚名 來源: IT168
相關推薦

2009-08-24 17:34:14

C#創建XML Web

2009-01-19 11:07:42

C#Web.NET

2009-09-03 17:36:13

C#創建Web應用程序

2009-08-20 15:38:50

C#建立Web Ser

2009-07-31 17:14:19

C#語言Web程序

2009-07-29 17:42:47

ibmdwWeb2.0

2009-08-27 11:53:45

ibmdw云計算

2009-08-13 17:04:09

C#語言C#程序

2009-08-11 13:27:22

C#創建Web Ser

2009-09-04 17:58:38

C# Web Brow

2009-08-20 17:49:53

學習C#程序

2009-08-17 17:16:19

C#實現在線升級

2009-08-19 17:11:49

C#程序集

2009-08-12 18:28:09

C#事件處理程序

2009-08-24 15:46:46

C# SmartPho

2009-08-13 17:15:44

C#屏幕保護程序

2009-08-20 10:48:05

C#做Screen C

2013-11-11 11:10:41

Amazon Web AWS云服務

2009-08-07 17:32:17

C#編譯程序

2009-08-11 11:07:49

Java調用C# we
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 午夜网站视频 | 欧美黄色一区 | 日韩精品视频在线观看一区二区三区 | www.日韩| 免费黄色网址视频 | 一区二区视频在线 | 久夜精品 | 亚洲人成网站777色婷婷 | av综合站| 亚洲精品一区二区三区四区高清 | 国产精品日产欧美久久久久 | 成年人在线观看 | 亚洲 中文 欧美 日韩 在线观看 | 91精品一区二区三区久久久久久 | 国产激情一区二区三区 | 成人国产在线视频 | 亚洲精品片 | 久草网免费| 久久综合狠狠综合久久综合88 | 日本精品视频一区二区 | 九九亚洲 | 91豆花视频| 久久免费精品视频 | 欧美精品一区二区三区在线四季 | 亚洲精品成人av久久 | 欧美日韩综合精品 | 91性高湖久久久久久久久_久久99 | 一级片在线观看 | 国产91在线观看 | 在线免费观看黄a | 青娱乐国产| а_天堂中文最新版地址 | 亚洲伊人久久综合 | 亚洲区在线 | 国内久久精品 | 免费午夜剧场 | 日韩国产一区二区 | 久久久久亚洲精品 | 一本久久a久久精品亚洲 | 日韩中文在线 | 久久久噜噜噜久久中文字幕色伊伊 |