7

在 C# 中重命名文件:

File.Move(source,Destination);
            File.Delete(source);

它成功执行,但是当我再次尝试重命名文件时,系统给出了这个异常: 该进程无法访问该文件,因为它正在被另一个进程使用。 我找不到这个在哪里使用?当我进一步调试错误时,它显示类名在 w3wp.exe 的进程中,即 IIS。接下来我该怎么办?得到

foreach (string folder in folder)
{ 
 FileSystemItem item = new FileSystemItem(); 
 DirectoryInfo di = new DirectoryInfo(folder); 
 item.Name = di.Name;
 item.FullName = di.FullName; 
 item.Path = path + "\\" + item.Name;
 item.CreatedDate = di.CreationTime; 
 item.IsFolder = true; 
 item.Extension = "folder";
 listFolder.Add(item);
}
docList = CreatXmllist(listFolder); 
return docList

这就是我获取文件夹列表的方式,然后将其返回到 xml。然后在文件夹中,当我单击它时我会得到文件

现在获取图像:这是代码

public xml (string path, List<l> one)
    {

        List<T> tt = new List<T>();
        List<T> SessionList = new List<T>();
        string[] files = Directory.GetFiles(HttpContext.Current.Request.PhysicalApplicationPath + path);

        foreach (string file in files)
        {
            FileSystemItem item = new FileSystemItem();
            FileInfo i = new FileInfo(file);
            string  a = i.LastWriteTime.ToString();
            var thumbnails = from a in b where a.Name == fi.Name select t;

            if (fi.Name != "a")
                if (t.Count() == 0)
                {
                    r session r = new r();
                    r.aName = fi.aName;
                    SessionList.Add(r);
                    fi.Exists;
                }
                else
                    t.Add((T)t.First());

        }
4

3 回答 3

2

您不需要调用 File.Delete 作为重命名的一部分,如果您进行了复制,您将需要它。

于 2011-03-01T09:53:45.397 回答
1

尝试使用 FileShare 枚举器。然后尝试使用 monesharing 打开文件,关闭句柄,如果没有异常,您可以移动文件。

http://msdn.microsoft.com/de-de/library/system.io.fileshare.aspx

它包含读取、写入等方法。

于 2011-03-01T09:54:27.317 回答
1

创建一个FileInfo实例,您可以在其中多次重命名它。

FileInfo file = new FileInfo(source);
file.MoveTo(destination);

// execute more code

file.MoveTo(destination2)
于 2011-03-01T10:05:00.907 回答