I believe that using ASP.NET writes a web page for uploading files. Everyone will write, but have anyone thinks to upload files through the HTTP protocol through the WinForm?
Some people say that the file is to be on the server, isn't it very simple to use the FTP protocol? The efficiency is high, why should I use the HTTP agreement so trouble? There are several reasons this:
(1) The deployment of the FTP server is relatively trouble, but also set permissions, permission settings are incorrect, will also provoke a series of security issues.
(2) If both parties have a firewall, do not want to develop some of the FTP-related ports, http will be used in the big use, just like web services to penetrate the firewall.
(3) Other ..., still thinking ...
But use HTTP and some of his problems, such as can't be broken, it is difficult to upload big files, slow speed, so the file size uploaded by HTTP protocol should not be too big.
Said so much, original home, in general, there are several optional methods to upload files in WinForm:
(1) The web services mentioned earlier is a good way to write a webMethod, including the parameters of the byte [] type, then call the web services method, the file content is transmitted to the server on the server. , Then re-save it.
[WebMethod] public void uploadfile (byte [] content, string filename) {stream sw = new streamwriter (...); SW.CLOSE ();} Of course, this method of efficiency through Base64 encoding is relatively low, then it can be used WSE, support attachments, and transferred in 2-en-enamded forms, efficiency will be higher. (2) In addition to the WebService, another simple method is to simulate the POST action of HTTP through WebClient or HttpWebRequest. At this time, you first need to write an ASP.NET web form to respond to upload, the code is as follows: <% @ page language = "c #" codebehind = "Webform1.aspx.cs" autoeventwireup = "false" inherits = "UploadFileWebformForm1"%>