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 }
vs2012上运行上传文件没有问题,发布到IIS上传文件提示上传目录文件被拒绝...
万能的博客园...
有没有人知道是什么权限问题