当前位置:
首页 > 编程开发 > Objective-C编程 >
-
C#的文件下载
这是一个运行在web服务器上并且监视c:\temp中的一个文本文件,如果发生了变化
它就自动将compPrj.dll从服务器下载到本地的c:\root目录。这个应用作为Windows 2000的服务安装并且用FileSystemWatcher组件监视文件。
注意: FileSystemWatcher 需要 .NET framework
System Requirement:
Windows2000
Microsoft .NET Framework Beta 1
Internet Information Server (IIS 5.0)
Visual Studio 7.0 Beta 1
Programming Language: C#
Purpose:
The purpose of this utility is to understand the following using .NET Framework:
-How to write and install Window Services,
-How to write internet Application using Http protocol.
-How to use Streams to read and write in a file.
Description:
File download utility is a web application which resides on the web server and monitors a txt file in c:\temp subdirectory. If it detects a change in this file, it downloads compPrj.dll from the web server ("http://localhost/files/compPrj.dll") to C:\ root directory. I have hardcoded file names and paths to simplify the program.
This Application is installed as Windows2000 Service and it uses FileSystemWatcher component for monitoring the files.
NOTE: FileSystemWatcher needs .NET framework.
The Application consist of two programs srvDownload.cs and srvInstaller.cs.
SrvDownload:
-SrvDownload is Windows2000 service class. From the VS IDE select windows Service project. A template class will be created with the constructor and all the required methods.
-In the InitializeComponent method assign the service a name( like srvDownload).
-In the Onstart method create an instance of FileWatcher component and set the following properties:
.Path The path of the file that is to be monitored.
.Target Indicates whether files, directory or both needs monitoring.
.ChangedFilters Specifies the changes to watch for in a file or folder. The possible values are:
.Attributes - The attributes of the file or folder.
.LastAccess - The date that the file or folder was last opened.
.LastWrite - The date that the file or folder was last written.
.Security - The security settings of the file or folder.
.Size - The size of the file or folder.
.Enabled Indicates whether the component is enabled.
.Filter Indicates what files are monitored in a directory. For all files use *.*, for Text use txt.
-Finally, add the Event handler. Since, this Application is only monitoring the CHANGED event therefore only onChanged event is added. However, you can add other events that you want to monitor such as onDelete or on Rename etc.
When a file is changed, the OnChange event is fired which downloads file CompPrj.dll from the web server to the client machine's
c:\ direcory. The download functionality uses .NET classes HttpWebResponse, HttpWebRequest. HttpWebRequest class manages the details of connecting to an Internet resource via Http. WebResponse class acts as a container for the incoming response. This response is then stored in a file using .NET I/O stream classes.
SrvInstaller.cs
An installer is needed to install the service therefore add installer to the same project solution. A template class will be created with the constructor.
In order to install services, ServiceInstaller and ServiceProcessInstaller classes from System.ServiceProcess namespace is required, one for the service and another for service process respectively.
Therefore instances of these classes is created inside the installer constructor. You can also set ServiceInstaller properties in the constructo such as Display Name, Service name etc. After setting the properties, add the service to Installers collection.
Service Installation:
-Build your project using VS Build.
-Install the service using InstallUtil from the Command prompt.
e.g. c:>installutil drvDownload.exe
-After successfully installing the utility, go to MyComputer and select Manage, this will take you to Computer Management screen. Select Services and you will see the drvDownload service.
-Start the Service.
-Change or Create a txt file in c:\temp subdirectory and this will download compprj.dll from the web server virtual directory files to c:\ root directory.
它就自动将compPrj.dll从服务器下载到本地的c:\root目录。这个应用作为Windows 2000的服务安装并且用FileSystemWatcher组件监视文件。
注意: FileSystemWatcher 需要 .NET framework
System Requirement:
Windows2000
Microsoft .NET Framework Beta 1
Internet Information Server (IIS 5.0)
Visual Studio 7.0 Beta 1
Programming Language: C#
Purpose:
The purpose of this utility is to understand the following using .NET Framework:
-How to write and install Window Services,
-How to write internet Application using Http protocol.
-How to use Streams to read and write in a file.
Description:
File download utility is a web application which resides on the web server and monitors a txt file in c:\temp subdirectory. If it detects a change in this file, it downloads compPrj.dll from the web server ("http://localhost/files/compPrj.dll") to C:\ root directory. I have hardcoded file names and paths to simplify the program.
This Application is installed as Windows2000 Service and it uses FileSystemWatcher component for monitoring the files.
NOTE: FileSystemWatcher needs .NET framework.
The Application consist of two programs srvDownload.cs and srvInstaller.cs.
SrvDownload:
-SrvDownload is Windows2000 service class. From the VS IDE select windows Service project. A template class will be created with the constructor and all the required methods.
-In the InitializeComponent method assign the service a name( like srvDownload).
-In the Onstart method create an instance of FileWatcher component and set the following properties:
.Path The path of the file that is to be monitored.
.Target Indicates whether files, directory or both needs monitoring.
.ChangedFilters Specifies the changes to watch for in a file or folder. The possible values are:
.Attributes - The attributes of the file or folder.
.LastAccess - The date that the file or folder was last opened.
.LastWrite - The date that the file or folder was last written.
.Security - The security settings of the file or folder.
.Size - The size of the file or folder.
.Enabled Indicates whether the component is enabled.
.Filter Indicates what files are monitored in a directory. For all files use *.*, for Text use txt.
-Finally, add the Event handler. Since, this Application is only monitoring the CHANGED event therefore only onChanged event is added. However, you can add other events that you want to monitor such as onDelete or on Rename etc.
When a file is changed, the OnChange event is fired which downloads file CompPrj.dll from the web server to the client machine's
c:\ direcory. The download functionality uses .NET classes HttpWebResponse, HttpWebRequest. HttpWebRequest class manages the details of connecting to an Internet resource via Http. WebResponse class acts as a container for the incoming response. This response is then stored in a file using .NET I/O stream classes.
SrvInstaller.cs
An installer is needed to install the service therefore add installer to the same project solution. A template class will be created with the constructor.
In order to install services, ServiceInstaller and ServiceProcessInstaller classes from System.ServiceProcess namespace is required, one for the service and another for service process respectively.
Therefore instances of these classes is created inside the installer constructor. You can also set ServiceInstaller properties in the constructo such as Display Name, Service name etc. After setting the properties, add the service to Installers collection.
Service Installation:
-Build your project using VS Build.
-Install the service using InstallUtil from the Command prompt.
e.g. c:>installutil drvDownload.exe
-After successfully installing the utility, go to MyComputer and select Manage, this will take you to Computer Management screen. Select Services and you will see the drvDownload service.
-Start the Service.
-Change or Create a txt file in c:\temp subdirectory and this will download compprj.dll from the web server virtual directory files to c:\ root directory.
最新更新
nodejs爬虫
Python正则表达式完全指南
爬取豆瓣Top250图书数据
shp 地图文件批量添加字段
爬虫小试牛刀(爬取学校通知公告)
【python基础】函数-初识函数
【python基础】函数-返回值
HTTP请求:requests模块基础使用必知必会
Python初学者友好丨详解参数传递类型
如何有效管理爬虫流量?
2个场景实例讲解GaussDB(DWS)基表统计信息估
常用的 SQL Server 关键字及其含义
动手分析SQL Server中的事务中使用的锁
openGauss内核分析:SQL by pass & 经典执行
一招教你如何高效批量导入与更新数据
天天写SQL,这些神奇的特性你知道吗?
openGauss内核分析:执行计划生成
[IM002]Navicat ODBC驱动器管理器 未发现数据
初入Sql Server 之 存储过程的简单使用
SQL Server -- 解决存储过程传入参数作为s
JavaScript判断两个数组相等的四类方法
js如何操作video标签
React实战--利用甘特图和看板,强化Paas平
【记录】正则替换的偏方
前端下载 Blob 类型整理
抽象语法树AST必知必会
关于JS定时器的整理
JS中使用Promise.all控制所有的异步请求都完
js中字符串的方法
import-local执行流程与node模块路径解析流程