关键代码如下
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”,因为该文件正由另一进程使用。

解决方案 »

  1.   

    应按是那里没有关闭,释放的原因.
    YES
      

  2.   

    前台代码主要系调用左javascript:
     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>&nbsp;
    <A class="a2" href="javascript:CopyMove('move');"><IMG alt="移动文件/文件夹" src="images/move.gif" border="0">移动文件/文件夹</A>&nbsp;下面是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>");
    }
    }