我想用 DirectoryInfo(string path) 为目录上传 FileInfo 文件
但我的 path = {D:\Documents and Settings\Administrator\桌面\picture}
目录确实是存在的 但.net总是提示 目录路径不正确
我的选择的路径 path 是客户端的
但在服务器端运行 DirectoryInfo(path) 的 Exists 属性 总是为false是不是用 DirectoryInfo(path) 不行啊
但我的 path = {D:\Documents and Settings\Administrator\桌面\picture}
目录确实是存在的 但.net总是提示 目录路径不正确
我的选择的路径 path 是客户端的
但在服务器端运行 DirectoryInfo(path) 的 Exists 属性 总是为false是不是用 DirectoryInfo(path) 不行啊
DirectoryInfo 只能用于服务端吗;
那用什么东东获得客户端的信息呢>
path =@"D:\Documents and Settings\Administrator\桌面\picture";
我觉得!
在前端aspx页面上引用下面JS:
<script language="JavaScript">
var i=2 ;
var j=0;
function insert_row()
{
i++ ;
R=tbl.insertRow() ;
R.id="add"+i;
C=R.insertCell() ;
var str = "<input type='file' name='File' id='File"+j+"' style='width:100%'>";
C.insertAdjacentHTML("beforeEnd",str); C=R.insertCell() ;
C.innerHTML="<input type='button' value='删除附件' class='buttoncss' onclick=this.parentElement.parentElement.removeNode(true);>" ;
j++;
}
</script>再在table下的td中搞个超链接引用上面JS中的函数,如:<A onclick="insert_row();" href="#">添加附件</A>
下面是,CS里面的代码:///'遍历File表单元素
在web.config文件中,随便设置"PrivateResPath" 的物理路径. 如:<add key="PrivateResPath" value="c:\Upload\PrivateRes\"/> string filePaths = System.Configuration.ConfigurationSettings.AppSettings["PrivateResPath"].ToString();
System.Text.StringBuilder strMsg = new System.Text.StringBuilder();
HttpFileCollection files = HttpContext.Current.Request.Files;
for (int iFile = 0; iFile < files.Count; iFile++)
{
///'检查文件扩展名字
HttpPostedFile postedFile = files[iFile];
string fileName, fileExtension;
fileName = System.IO.Path.GetFileName(postedFile.FileName);
if (fileName != "")
{
fileExtension = System.IO.Path.GetExtension(fileName);
strMsg.Append("上传的文件类型:" + postedFile.ContentType.ToString() + "<br>");
strMsg.Append("客户端文件地址:" + postedFile.FileName + "<br>");
strMsg.Append("上传文件的文件名:" + fileName + "<br>");
strMsg.Append("上传文件的扩展名:" + fileExtension + "<br><hr>");
///'可根据扩展名字的不同保存到不同的文件夹
///注意:可能要修改你的文件夹的匿名写入权限。
//postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("images/") + fileName);
postedFile.SaveAs(filePaths + fileName);
}
} 你研究下吧
path = {D:\\Documents and Settings\\Administrator\\桌面\\picture}