当前位置:编程学习 > C#/ASP.NET >>

急!!!!! 一个关于图片上传到远程服务器代码出错的问题.

代码如下:
         string galleryPath =  "\\192.168.148.168\isd-photo" + "\\";
         HttpPostedFile sourceFile = Request.Files["SourceFile_1"];
          string fileName = Path.GetFileName(sourceFile.FileName);

            String folder_ref = Request.Form["FOLDERREF"].ToString();

            string year = DateTime.Now.Year.ToString();
            string month = DateTime.Now.Month.ToString();
            
            string dirPath = galleryPath + year  +"年/" + month + "月/" + folder_ref;
        
            if (!Directory.Exists(Server.MapPath(dirPath)))
            {
                Directory.CreateDirectory(Server.MapPath(dirPath));
            }

            Request.Files["SourceFile_1"].SaveAs(Server.MapPath(dirPath + "/O_" + fileName));
            Request.Files["Thumbnail1_1"].SaveAs(Server.MapPath(dirPath + "/S_" + fileName));

            Request.Files["Thumbnail2_1"].SaveAs(Server.MapPath(dirPath + "/B_" + fileName));
当运行到:if (!Directory.Exists(Server.MapPath(dirPath))) 报错:Failed to map the path '/192.168.148.168/isd-photo/2008年/11月/20080805A'.
大家帮帮忙啊!!!!!
--------------------编程问答-------------------- 沙发啊!
路径是相对路径吗?你的192.168.148.168?IP   还是服务器的IP
--------------------编程问答-------------------- 服务器的IP --------------------编程问答-------------------- string dirPath = galleryPath + year  +"年/" + month + "月/" + folder_ref; 
        
            if (!Directory.Exists(Server.MapPath(dirPath))) 
            { 
                Directory.CreateDirectory(Server.MapPath(dirPath)); 
            } 
///////////////////////////////////////////////////////////////
改为:
string dirPath = Server.MapPath(galleryPath);
dirPath = dirPath + "\\" + year  +"年\\" + month + "月\\" + folder_ref + "\\"; 
if (!Directory.Exists(Server.MapPath(dirPath))) 
            { 
                Directory.CreateDirectory(Server.MapPath(dirPath)); 
            } 
试试。
Server.MapPath的参数所指的目录不存在的时候,会不会报错,我没有试
--------------------编程问答-------------------- mark --------------------编程问答-------------------- 没用,还是报原来一样的错
--------------------编程问答-------------------- 不应该带 192.168.148.168吧, --------------------编程问答-------------------- if (!Directory.Exists(galleryPath + dirPath)) 
这样行不?
--------------------编程问答-------------------- string galleryPath =  @"\\192.168.148.168\isd-photo\";


而且你这个share isd-photo在192.168.148.168给程序运行的帐号有写的权限. --------------------编程问答-------------------- asp.net 局域网内共享目录的访问方法:

http://topic.csdn.net/u/20080421/22/4c2c8a27-d914-4c3c-bf26-229ecca3e34f.html 

1.
Web.Config中设置asp.net运行的帐号
<identity impersonate="true" userName="filestorage" password="123456"/>

2.
在 asp.net运行的系统和文件存储服务器的系统中新建以 filestorage 为用户名, 123456为密码的帐号,并赋予相应的权限。

3.
文件存储服务器上设置好了帐号之后,在新建一个sharebing并赋予filestorage帐号的权限

4.
Web server的asp.net程序上就可以通过\\serverName(IP)\shareName\.. 来访问共享出来的文件夹了。 --------------------编程问答-------------------- 不带 192.168.148.168这个怎么行,因为是要把图片上传到这个服务器IP指定的路径下面去,还是抱一样的错 --------------------编程问答-------------------- 按照我的方法一步一步来 --------------------编程问答-------------------- 8楼说的有道理,你用什么用户上传文件?这个账户在192.168.148.168这个服务器上有写的权限吗?
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,