Hello,
OM Partners wrote:Is this issue solved in a more recent version of TeeChart?
This issue is a common problem when saving files to disk. The issue here is that there is no way to close an open file without killing the process that has it open first. In the case of a pdf file, this means enumerating every open process on the machine and best-guessing which process is holding the file open. This is not only unreliable, it could also be very inconvenient to a user to have one of their processes killed automatically.
My best suggesting then is that you either:
1) use a unique file name for each file you save using a datetime stamp.
2) inform the user of the open file and suggest that they close it, e.g.
Code: Select all
private void button1_Click(object sender, EventArgs e)
{
string fileName = @"D:\tmp\chart.pdf";
if(!CheckFileOpen(fileName)) tChart1.Export.Image.PDF.Save(fileName);
}
private bool CheckFileOpen(string fileName)
{
if(!File.Exists(fileName))
{
return false;
}
else
{
try
{
Stream s = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.None);
s.Close();
return false;
}
catch (Exception)
{
MessageBox.Show("File " + fileName + " is open. Please close it.");
return true;
}
}
}