关键代码如下
private void LbtnCopyMove_Click(object sender, System.EventArgs e)
{
bool redir=true;
string folder=funcParam.Value;
string op=funcExtraParam.Value; if(!folderPath.StartsWith("/"))
{
if(!folderPath.EndsWith("/"))
folder=folderPath+folder;
else
folder=folderPath+"/"+folder;
}
folder=Server.MapPath(folderPath); foreach(TableRow tr in FoldersAndFiles.Rows)
{
if(tr.Cells[0].Controls.Count==2)
{
CheckBox checkItem=(CheckBox)tr.Cells[0].Controls[0];
if(checkItem.Checked)
{
string destPath=Path.Combine(folder,((HyperLink)tr.Cells[1].Controls[0]).Text);
string path=Server.MapPath(checkItem.Attributes["Path"].ToString());
try
{
if(Convert.ToBoolean(checkItem.Attributes["IsFile"])==true)
{
if(op=="move")
File.Move(path,destPath);
else
File.Copy(path,destPath,true);
}
else
{
if(op=="move")
Directory.Move(path,destPath);
else
CopyDirectory(path,destPath,true);
}
}
catch(Exception ex)
{
throw ex;
}
}
}
}
}运行出现如此错误:
该进程无法访问文件“D:\ASP.NET\FileManager\a.txt”,因为该文件正由另一进程使用。
private void LbtnCopyMove_Click(object sender, System.EventArgs e)
{
bool redir=true;
string folder=funcParam.Value;
string op=funcExtraParam.Value; if(!folderPath.StartsWith("/"))
{
if(!folderPath.EndsWith("/"))
folder=folderPath+folder;
else
folder=folderPath+"/"+folder;
}
folder=Server.MapPath(folderPath); foreach(TableRow tr in FoldersAndFiles.Rows)
{
if(tr.Cells[0].Controls.Count==2)
{
CheckBox checkItem=(CheckBox)tr.Cells[0].Controls[0];
if(checkItem.Checked)
{
string destPath=Path.Combine(folder,((HyperLink)tr.Cells[1].Controls[0]).Text);
string path=Server.MapPath(checkItem.Attributes["Path"].ToString());
try
{
if(Convert.ToBoolean(checkItem.Attributes["IsFile"])==true)
{
if(op=="move")
File.Move(path,destPath);
else
File.Copy(path,destPath,true);
}
else
{
if(op=="move")
Directory.Move(path,destPath);
else
CopyDirectory(path,destPath,true);
}
}
catch(Exception ex)
{
throw ex;
}
}
}
}
}运行出现如此错误:
该进程无法访问文件“D:\ASP.NET\FileManager\a.txt”,因为该文件正由另一进程使用。
解决方案 »
- 获取汉字拼音的问题,网上找到的经常有识别不到的……
- 这个.Skin文件写的有问题吗?
- vs2008的GridView控件中,如何实现修改数据后,提示保存?
- 请问大家用Asp.net来开发的时候是如何处理对数据库访问的并发操作的?
- 自定义控件使用问题?
- aspx页上传数据库问题!
- ACCESS insert的问题!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- DropDownList问题!在线等待!!
- 怎样在webform中实现一combobox控件绑定一表啊?
- 关于在页面中传递中文的问题?
- 开发完成的ASP.NET程序,第三工具调用登录界面时如何把用户名、密码带进去?急!线等!
- 按钮提交时到服务器时,因速度影响,界面来不及刷新时,如果多次点击按钮就会出出多次提交现象
YES
function CopyMove(op)
{
destPath=prompt('请输入相对路径','');
if((destPath) && (destPath!=""))
{
document.forms['BrowseFiles'].elements['funcParam'].value=destPath;
document.forms['BrowseFiles'].elements['funcExtraParam'].value=op;
__doPostBack('LbtnCopyMove','');
}
}激发javascript的控件:
<A class="a2" href="javascript:CopyMove('copy');"><IMG alt="复制文件/文件夹" src="images/copy.gif" border="0">复制文件/文件夹</A>
<A class="a2" href="javascript:CopyMove('move');"><IMG alt="移动文件/文件夹" src="images/move.gif" border="0">移动文件/文件夹</A> 下面是CopyDirectory函数的代码:
private void CopyDirectory(string sourcePath,string destPath,bool overwrite)
{
DirectoryInfo sourceDir=new DirectoryInfo(sourcePath);
DirectoryInfo destDir=new DirectoryInfo(destPath); if(sourceDir.Exists)
{
if(!destDir.Parent.Exists)
Response.Write("<script>window.alert('文件夹不存在')</script>"); if(!destDir.Exists)
destDir.Create(); foreach(FileInfo file in sourceDir.GetFiles())
{
if(overwrite)
file.CopyTo(Path.Combine(destDir.FullName,file.Name),true);
else
{
if(!File.Exists(Path.Combine(destDir.FullName,file.Name)))
file.CopyTo(Path.Combine(destDir.FullName,file.Name),false);
}
} foreach(DirectoryInfo dir in sourceDir.GetDirectories())
CopyDirectory(dir.FullName,Path.Combine(destDir.FullName,dir.Name),overwrite); }
else
{
Response.Write("<script>window.alert('源文件不存在')</script>");
}
}