7

C# でファイルの名前を変更する:

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

正常に実行されますが、ファイルの名前を再度変更しようとすると、システムは次の例外を返し ます。別のプロセスで使用されているため、プロセスはファイルにアクセスできません。 これがどこで使用されているのかわかりませんか?エラーをさらにデバッグすると、クラス名が IIS である w3wp.exe のプロセスにあることがわかります。次に何をすればいいですか?取得

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

FileInfoインスタンスの名前を複数回変更できるインスタンスを作成します。

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

// execute more code

file.MoveTo(destination2)
于 2011-03-01T10:05:00.907 に答える
1

FileShare 列挙子を使用してみてください。次に、マネーシェアリングでファイルを開こうとし、ハンドルを閉じて、例外がなければファイルを移動できます。

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

Read、Writeなどのメソッドが含まれています。

于 2011-03-01T09:54:27.317 に答える