又是上传文件问题,但绝对不同。远程上传文件失败!(源码奉上)

jackiedlh 2003-07-21 11:10:42
下面是我上传文件的一个函数:serverFilePath是上传到服务器的目录,clientPathFileName是客户端的完全文件名(包括目录)

protected void UpLoadFile(string serverFilePath, string clientPathFileName)
{
WebClient webClient = new WebClient();
if (!File.Exists(serverFilePath))
{
Directory.CreateDirectory(serverFilePath);
}

string[] arrCurrentFileName = ( string[] ) clientPathFileName.Split( '\\' );
string fileName = arrCurrentFileName[ arrCurrentFileName.GetUpperBound( 0 ) ];

webClient.UploadFile(serverFilePath + fileName ,clientPathFileName);
}

调试时是服务器与客户端是在同一计算机上,上传成功!!
但在另一台计算机,用IE运行我服务器上的程序,也上传同样的文件(大小一样),但总是提示:WebClient请求期间发生异常!

谁救我呀!
...全文
73 10 打赏 收藏 举报
写回复
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
jackiedlh 2003-07-21
  • 打赏
  • 举报
回复
都设置了,包括上机目录
是不是要用到remoting, 或者改用FTP法(也没用过,不知会有什么问题)

谁上传过文件,给个例子(能远程上传文件),让在下研究研究!
非常感谢!

solo108 2003-07-21
  • 打赏
  • 举报
回复
请将上传文件夹的上级目录也把权限放开,试它一试!
pinghero 2003-07-21
  • 打赏
  • 举报
回复
我也遇到过同样的问题,通过代理上网得或局域网的客户端都不成功,在这里问过,现在也没搞清为什么! 顶!!
jackiedlh 2003-07-21
  • 打赏
  • 举报
回复
把大家也难住了??

斑竹能救我吗?
jackiedlh 2003-07-21
  • 打赏
  • 举报
回复
上传的文件夹在IIS服务器的物理目录下,已经设置了web共享,而且设置了许可所有everyone操作(包括写入,暂时不考虑安全问题了)。
是不是还有什么设置?
问题是在本机浏览器能正常上传文件,为什么非本机就不行,而且还是局域网上的客户端??
纳闷。。。
  • 打赏
  • 举报
回复
没错,上传目录的写权限是否打开?
szhuk 2003-07-21
  • 打赏
  • 举报
回复
检查一下权限,可能你要上传的文件夹没有写入的权限
jackiedlh 2003-07-21
  • 打赏
  • 举报
回复
解决,不用webclient!
特别鸣谢goody9807!
goody9807 2003-07-21
  • 打赏
  • 举报
回复
</script>
</head>
<body>
<center>
<h3> 文件上传的实例, 来自<a href="http://www.chinabs.net">中国BS网</a></h3>
<form id="uploderform" method="post" action="FileUpload.aspx" enctype="multipart/form-data" runat="server" >
<table border="1" cellspacing="2" cellpadding="2" >
<tr> <td><h5>选择要上传的文件:</h5></td</tr>
<tr>
<td>
<input type="file" id="myFile" runat="server" NAME="myFile">
</td>
</tr>
<tr><td>
<input type="button" value="上 传" OnServerClick="UploadFile" runat="server" ID="Button1" NAME="Button1">
</td></tr>
</table>
</form>
<br>
<br>
<table border="1" cellspacing="2">
<tr><td><b>文件资料</b></td>
<td> </td>
</tr>
<tr>
<td>文件名 :</td>
<td><asp:label id="fname" text="" runat="server" /></td></tr>
<tr>
<td>文件类型 :</td>
<td><asp:label id="fenc" runat="server" /></td></tr>
<tr>
<td>文件大小 :(in bytes)</td>
<td><asp:label id="fsize" runat="server" /></td></tr>
</table>
<br>
<br>
<br>
</center>
</body>
</html>
goody9807 2003-07-21
  • 打赏
  • 举报
回复
<%@ Import Namespace="System.IO" %>
<%@ page Language="C#" debug="true" %>
<html>
<head>
<title>上传文件 , http://www.chinabs.net </title>
<script language="C#" runat="server">
//This method is called when the "upload" button id pressed
public void UploadFile(object sender , EventArgs E)
{
//检查上传文件不为空
if(myFile.PostedFile!=null)
{
string nam = myFile.PostedFile.FileName ;
//取得文件名(抱括路径)里最后一个"."的索引
int i= nam.LastIndexOf(".");
//取得文件扩展名
string newext =nam.Substring(i);
//这里我自动根据日期和文件大小不同为文件命名,确保文件名不重复
DateTime now = DateTime.Now;
string newname=now.DayOfYear.ToString()+myFile.PostedFile.ContentLength.ToString();
//保存文件到你所要的目录,这里是IIS根目录下的upload目录.你可以改变.
//注意: 我这里用Server.MapPath()取当前文件的绝对目录.在asp.net里"\"必须用"\\"代替
myFile.PostedFile.SaveAs(Server.MapPath("\\upload\\"+newname+newext));
//得到这个文件的相关属性:文件名,文件类型,文件大小
fname.Text=myFile.PostedFile.FileName;
fenc.Text=myFile.PostedFile.ContentType ;
fsize.Text=myFile.PostedFile.ContentLength.ToString();
}
}
发帖
.NET社区

6.1w+

社区成员

.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
帖子事件
创建了帖子
2003-07-21 11:10
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。