比如说网站是http://localhost/ReceiveFile/DownLoadPhotos.aspx,想要通过winform获取ReceiveFile下的photos文件夹下的所有文件,winform通过uri路径不能访问,那该怎么做啊

解决方案 »

  1.   

    ftpwebrequest访问文件夹
    文件可通过webclient下载
      

  2.   

    这是我在服务器端写的代码,从客户端接受文件夹名,然后再返回给客户端这个文件夹下所有文件,这个如何来写啊,下面写的不一定对,不知道怎么才能把文件夹下文件返回给客户端,也不知道如何通过客户端来给服务器端传值,各位高手救救我把
    for (int i = 0; i < Request.Files.Count; i++)
            {
                string fileName = Path.GetFileName(Request.Files[i].FileName);
                
                string fileP = Server.MapPath("~/files/");
                string filePath = Server.MapPath("~/files/photos/") + fileName;
                string[] fileNames = Directory.GetFiles(filePath);
                List<string> list = new List<string>();
                foreach (string file in fileNames)
                {
                    list.Add(file);
                }
                for (int j = 0; j < list.Count; i++)
                {
                    Response.Headers.Add(i.ToString(), list[i]);
                }
                
            }
      

  3.   

    void DownUpdateFile()
            {
                this.Cursor = Cursors.WaitCursor;
                
                WebClient wcClient = new WebClient();
                for (int i = 0; i <= this.lvUpdateList.Items.Count; i++)
                {
                    string UpdateFile = string.Empty;
                    if (i < lvUpdateList.Items.Count)
                        UpdateFile = lvUpdateList.Items[i].Text.Trim();
                    else
                        UpdateFile = "UpdateList.xml";                string updateFileUrl = _updateUrl + UpdateFile;
                    long fileLength = 0;                WebRequest webReq = WebRequest.Create(updateFileUrl);
                    WebResponse webRes = webReq.GetResponse();
                    fileLength = webRes.ContentLength;                lbState.Text = "正在下载更新文件,请稍后...";
                    pbDownFile.Value = 0;
                    pbDownFile.Maximum = (int)fileLength;                try
                    {
                        Stream srm = webRes.GetResponseStream();
                        StreamReader srmReader = new StreamReader(srm);
                        byte[] bufferbyte = new byte[fileLength];
                        int allByte = (int)bufferbyte.Length;
                        int startByte = 0;
                        while (fileLength > 0)
                        {
                            Application.DoEvents();
                            int downByte = srm.Read(bufferbyte, startByte, allByte);
                            if (downByte == 0) { break; };
                            startByte += downByte;
                            allByte -= downByte;
                            pbDownFile.Value += downByte;                        float part = (float)startByte / 1024;
                            float total = (float)bufferbyte.Length / 1024;
                            int percent = Convert.ToInt32((part / total) * 100);
                            if (i < lvUpdateList.Items.Count)
                                this.lvUpdateList.Items[i].SubItems[2].Text = percent.ToString() + "%";
                        }
                        string tempPath = _tempUpdatePath + UpdateFile;
                        CreateDirtory(tempPath);
                        FileStream fs = new FileStream(tempPath, FileMode.OpenOrCreate, FileAccess.Write);
                        fs.Write(bufferbyte, 0, bufferbyte.Length);
                        srm.Close();
                        srmReader.Close();
                        fs.Close();
                    }
                    catch (WebException ex)
                    {
                        MessageBox.Show("更新文件下载失败,\r\n请联系系统管理员下载完整安装文件!" + ex.Message.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                InvalidateControl();
                this.Cursor = Cursors.Default;
            }