日期:2014-05-18  浏览次数:20377 次

下载图片 问题 求高手解答
前台调用js
JScript code

function uplond() {
            var oImg = document.getElementById("mainphoto");
            ImgUploadManger.imgView.uploadImg(location.protocol + '//' + location.host + "/", oImg.src, window.location.search, oImg.width, oImg.height);
            alert('下载成功、存放在D盘根目录下!');            
                    }


后台
 
C# code

[AjaxPro.AjaxMethod]
        public void uploadImg(string _physicalApplicationPath, string _src, string _search, int _width, int _heigth)
        {
            //获取比例图的大小
            int width = _width;
            int height = _heigth;
            _src = _src.Replace(_physicalApplicationPath, "");
            //生成比例图
            Images img = new Images();
            string src = img.Thumbnail1(Server.MapPath("../") + _src, width, height);
            string filepath = src;
            string urlpath = src.Replace(Server.MapPath("../"), "");
            string filename = System.IO.Path.GetFileName(filepath);
            try
            {
             //这里是下载
                WebClient wc = new WebClient();
                wc.DownloadFile(_physicalApplicationPath + urlpath, "d:\\" + filename);
                wc.Dispose();                 
            }
            catch (Exception ex)
            {
                ClientScript.RegisterStartupScript(typeof(string), "Err", string.Format("<script language='javascript'>alert('{0}');</script>", ex.Message));
                return;
            }
            
        }       


  问题:在VS运行的时候、比例图生成了 d:也下载了比例图
  但是我挂在本地IIS里面、比例图生成了,怎么也下载不到比例图片 D:没东西
  求解

------解决方案--------------------
应该还是路径问题,仔细检查一下,仿着比例图的路径作法,Server.MapPath
------解决方案--------------------
行号 98:wc.DownloadFile(_physicalApplicationPath + urlpath, "d:\\" + filename);
应该是路径问题, 再好好查查看, 用VS调试不行吗? 应该不依赖IIS的

你调用的地方你先填写 一个你知道的绝对路径先调试。 再下面调用的代码里 先输出这个路径看看
到底输出的是什么。

_src = _src.Replace(_physicalApplicationPath, "");
你这里替换的是什么呢?