다음 코드는 '프로세스가 파일에 액세스 할 수 없습니다'라는 메시지가있는 System.IO.IOException을 제공합니다.C1ZipFile을 사용한 후에이 파일을 삭제할 수없는 이유는 무엇입니까?
private void UnPackLegacyStats()
{
DirectoryInfo oDirectory;
XmlDocument oStatsXml;
//Get the directory
oDirectory = new DirectoryInfo(msLegacyStatZipsPath);
//Check if the directory exists
if (oDirectory.Exists)
{
//Loop files
foreach (FileInfo oFile in oDirectory.GetFiles())
{
//Check if file is a zip file
if (C1ZipFile.IsZipFile(oFile.FullName))
{
//Open the zip file
using (C1ZipFile oZipFile = new C1ZipFile(oFile.FullName, false))
{
//Check if the zip contains the stats
if (oZipFile.Entries.Contains("Stats.xml"))
{
//Get the stats as a stream
using (Stream oStatsStream = oZipFile.Entries["Stats.xml"].OpenReader())
{
//Load the stats as xml
oStatsXml = new XmlDocument();
oStatsXml.Load(oStatsStream);
//Close the stream
oStatsStream.Close();
}
//Loop hit elements
foreach (XmlElement oHitElement in oStatsXml.SelectNodes("/*/hits"))
{
//Do stuff
}
}
//Close the file
oZipFile.Close();
}
}
//Delete the file
oFile.Delete();
}
}
}
파일이 잠길 수있는 곳을 확인하는 중입니다. 파일 핸들을 붙잡을 수있는 모든 객체는 블록을 사용하고 명시 적으로 닫힙니다.
정적 GetFiles 메서드에서 반환 한 문자열 대신 FileInfo 개체를 사용하면 어떻게됩니까?
아이디어가 있으십니까?
어디에서 예외가 발생합니까? –
@Joshua - On oFile.Delete(); – stevehipwell