日期:2014-05-20  浏览次数:20369 次

WebClient.UploadFile方法的问题
我找了好多资料,没发现什么问题呀?运行就是没反应。
上传的事件是这样写的:
System.Net.WebClient   wc   =   new   System.Net.WebClient();
                        wc.Credentials   =   new   System.Net.NetworkCredential( "IUSR_DBOYJQ ",   "admin ");
                        try
                        {
                                foreach   (ListViewItem   item   in   fileList.Items)
                                {
                                        wc.UploadFile( "http://***/FileUpload.aspx ",   "post ",   item.Text);
                                }
                        }
                        catch   (Exception   ex)
                        {
                                MessageBox.Show(ex.ToString());
                                return;
                        }

                        MessageBox.Show( "上传成功! ");

FileUpload.aspx的代码,除了form都自动生成的:
<%@   Page   Language= "C# "   AutoEventWireup= "false "   CodeFile= "FileUpload.aspx.cs "   Inherits= "IDSData_FileUpload "   %>

<!DOCTYPE   html   PUBLIC   "-//W3C//DTD   XHTML   1.0   Transitional//EN "   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<html   xmlns= "http://www.w3.org/1999/xhtml "   >
<head   runat= "server ">
        <title> 无标题页 </title>
</head>
<body>
        <form   id= "form1 "   method= "post "   enctype= "multipart/form-data "   runat= "server ">
        </form>
</body>
</html>

Page_Load方法:
        protected   void   Page_Load(object   sender,   EventArgs   e)
        {
                foreach   (string   f   in   Request.Files.AllKeys)
                {
                        HttpPostedFile   file   =   Request.Files[f];
                        file.SaveAs(@ "C:\Temp\ "   +   file.FileName);
                }