从服务器下载到客户端

/// <summary>
        /// 文件下载
        /// </summary>
        /// <param name="folder">文件夹名称</param>
        /// <param name="fileName">文件名和后缀</param>
        /// <returns></returns>
        public static string DownLoad(string folder, string fileName)
        {
            fileName = string.Format("{0}/{1}", folder, fileName);
            string path = "";
            try
            {

                string filePath = string.Format("{0}/{1}", Common.GetServerPath(), fileName);

                path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, folder);
                //如果不存在就创建文件夹
                if (System.IO.Directory.Exists(path) == false)
                {
                    System.IO.Directory.CreateDirectory(path);
                }

                System.Net.WebClient c = new System.Net.WebClient();

                FileInfo fi = new FileInfo(fileName);
                if (fi.Exists)
                {
                    //如果存在先删除后下载
                    fi.Delete();
                }
                //下载更新文件
                c.DownloadFile(filePath, fileName);

                path = string.Format("{0}\\{1}", path, Path.GetFileName(filePath));
            }
            catch (Exception ex)
            {
                path = "导入报错:" + ex.Message;
            }
            return path;
        }

 


版权声明:本文为GuangXing_HuangXuLin原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。