Quantcast
Channel: 尘封的记忆
Viewing all articles
Browse latest Browse all 46

在winform中使用WebClient上传文件

$
0
0

 

 winform中的upload事件:   

  private   void   FileUpload(string   address,   string   category)   

  {   

  WebClient   myWebClient   =   new   WebClient();   

  myWebClient.UploadFile("http://localhost/cmp/test/winupload.aspx?category="+category,"POST",address);   

  }   

  ----------------------------------------------------------------   

  winupload.aspx中:   

  private   void   Page_Load(object   sender,   System.EventArgs   e)   

  {   

  string   category   =   Request.Params["category"].ToString();   

    

  foreach(   string   f   in   Request.Files.AllKeys)   

  {   

  HttpPostedFile   file   =   Request.Files[f];   

  file.SaveAs(@"C:\Inetpub\wwwroot\cmp\Uploaded\"+   category   +   @"\"   +   file.FileName);   

  }   

  if(   Request.Params["testKey"]   !=   null   )   

  {   

  Response.Write(Request.Params["testKey"]);   

  }   

注意:把IIS设为允许匿名访问就不会出现问题 或者开通webdev。


Viewing all articles
Browse latest Browse all 46

Trending Articles