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 not correct, will also provoke a series of security issues.
(
2
If both parties have firewalls, they do not want to develop some port related to FTP, http will be used to use, just like Web Services can wear firewalls.
(
3
) Other ..., still think ...
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 include a WebMethod, including
Byte
[] Parameters of the type, then call the web services, the file content is transmitted to the server as Base64, and then re-save.
[WebMethod]
public
Void
UPLOADFILE
Byte
Content,
String
Filename)
...
{
Street SW = new streamwriter (...);
SW.CLOSE ();
}
Of course, this method of efficiency by Base64 encoding is relatively low, then WSE can be employed, and attachments can be used, and the efficiency will be higher in 2 envelopes.
(
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:
hEAD>