首页 新闻 会员 周边

WebClient.OpenWrite 上传文件到共享目录访问被拒绝

0
悬赏园豆:40 [已关闭问题] 关闭于 2016-02-20 08:49
 1 public void UpLoadFileToService(HttpPostedFile postfile, string newFileName, string urlPath, string userName, string password)
 2         {
 3             //var newFileName =  fileNamePath.Substring(fileNamePath.LastIndexOf(@"\", StringComparison.Ordinal) + 1);//取文件名称
 4             if (urlPath.EndsWith(@"\") == false) urlPath = urlPath + @"\";
 5 
 6             try
 7             {
 8                 var myWebClient = new System.Net.WebClient();
 9                 var cread = new System.Net.NetworkCredential(userName, password, "Domain");
10                 myWebClient.Credentials = cread;
11 
12                 int fileLen = postfile.ContentLength;
13                 var imgArray = new byte[fileLen];
14                 postfile.InputStream.Read(imgArray, 0, fileLen);
15 
16                 //if (!Directory.Exists(urlPath))
17                 //{
18                 //    Directory.CreateDirectory(urlPath);
19                 //}
20 
21                 Uri addy = new Uri(urlPath + newFileName);
22                 myWebClient.Credentials = cread;
23                 myWebClient.UploadData(addy, imgArray);
24 
25                 myWebClient.Dispose();
26 
27                 //var postStream = myWebClient.OpenWrite(urlPath + newFileName, "PUT");
28                 //if (postStream.CanWrite)
29                 //{//上传 
30                 //    postStream.Write(imgArray, 0, imgArray.Length);
31                 //}
32                 //else
33                 //{//上传失败
34                 //    throw new MessageException("上传文件失败!");
35                 //}
36 
37                 //postStream.Close();
38             }
39             catch (Exception ex)
40             {
41                 //上传异常
42                 throw new MessageException("上传文件异常:" + ex.Message);
43             }
44         }
View Code

vs2012上运行上传文件没有问题,发布到IIS上传文件提示上传目录文件被拒绝...

万能的博客园...

有没有人知道是什么权限问题

拾梦小侠ด้้้的主页 拾梦小侠ด้้้ | 小虾三级 | 园豆:713
提问于:2016-02-18 16:51
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册