There are many online programs, at first, because the net is not very familiar with the FTP implementation is good, but later found that if the machine in the domain control, there will be problems.
A year later, ASP. NET is also familiar with, know Ajax should use ASHX, verification code also with ASHX, of course, here to say WinForm upload should also be ashx, haha, first provide a simple idea:
The ASP. Net of the received file is: UPLOADER.ASHX, related code:
View Plaincopy to Clipboardprint?
- <%@ WebHandler language="C #" class="Uploader"%>
- Using System;
- Using System.IO;
- Using System.Web;
- Public class Uploader:ihttphandler
- {
- public void ProcessRequest (HttpContext hc)
- {
- foreach (string filekey in HC. Request.Files)
- {
- Httppostedfile file = hc. Request.files[filekey];
- File. SaveAs (Path.Combine (HC). Server.MapPath ("."), file. FileName));
- }
- }
- public bool IsReusable
- {
- get { return true;}
- }
- }
Send WinForm.cs related code for a picture or file:
View Plaincopy to Clipboardprint?
- System.Net.WebClient mywebclient = new System.Net.WebClient ();
- Mywebclient.uploadfile ("Http://www.yongfa365.com/Uploader.ashx", "POST", " c:\\windows\\system32\\ Cmd.exe ");
OK, finished, so operation, no longer do not have to control the domain control, as long as the internet can be uploaded. It's convenient enough.
If you want to bulk upload, and upload after the save in which directory and other operations can refer to LIUYONGFA (yongfa365) ' blog written:
The ASP. Net of the received file is: UPLOADER.ASHX, related code:
View Plaincopy to Clipboardprint?
- <%@ WebHandler language="C #" class="Uploader"%>
- Using System;
- Using System.IO;
- Using System.Web;
- Public class Uploader:ihttphandler
- {
- public void ProcessRequest (HttpContext hc)
- {
- string nowpath = Path.Combine (hc. Server.MapPath ("."), HC. request["path"]);
- if (! Directory.Exists (Nowpath))
- {
- Directory.CreateDirectory (Nowpath);
- }
- foreach (string filekey in HC. Request.Files)
- {
- Httppostedfile file = hc. Request.files[filekey];
- string FilePath = Path.Combine (nowpath, file. FileName);
- if (file.exists (FilePath))
- {
- if (Convert.toboolean (HC. request["overwrite"]))
- {
- File.delete (FilePath);
- }
- Else
- {
- continue;
- }
- }
- File. SaveAs (FilePath);
- }
- }
- public bool IsReusable
- {
- get { return true;}
- }
- }
Send WinForm.cs related code for a picture or file:
View Plaincopy to Clipboardprint?
- string url = @ "http ://www.yongfa365.com/uploader.ashx? Overwrite=true&path=logs\ " + datetime.now.tostring (" Yyyy-mm-dd ");
- foreach (string file in directory.getfiles (item)
- {
- system.net.webclient mywebclient = new system.net.webclient ();
- mywebclient.uploadfile (Url, "POST", file);
- }