file renaming problem?

Renaming a file in c#:

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

It execute successfully, how ever when i try to rename the file again, the system gives this exception: The process cannot access the file because it is being used by another process. i cant find that where is this in use? when i further debug the error it shows me the class name is in the process of w3wp.exe which is IIS. What should i do next? getting

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

this is how i am getting folder list and it is then returned to xml. then in folder i get the files when i click it

now to get the images: this is the code

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());

        }

你不需要调用File.Delete作为重命名的一部分,如果你做了一个副本,你将需要它。


Try using the FileShare enumerator. Then try to open a file with monesharing, close the handle and if there is no exception you can move the file.

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

It contains the methods Read, Write etc.


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

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

// execute more code

file.MoveTo(destination2)
链接地址: http://www.djcxy.com/p/51196.html

上一篇: arg和属性一起在bean中定义

下一篇: 文件重命名问题?