Hello,
When i save in c# a autocad document dwg, i have exception efileinternalerror.
I use doc.Database.save.
I want save dwg in current filename dwg , the methode File.Copy throw exception file already used.
File.Delete throw exception file already used.
Thank.
internal static void SaveDoc(Document doc)
{
//using (Transaction tr = doc.Database.TransactionManager.StartTransaction())
//{
// doc?.Database?.Save();
// tr.Commit();
//}
bool ok = false;
try
{
using (DocumentLock docLock = doc.LockDocument())
{
// Sauvegarder toutes les modifications
doc.Database.Save(); // Si possible
ok = true;
}
}
catch (System.Exception ee)
{
CGV.RecordingException(ee, "SaveDoc", false);
}
if (!ok)
{
try
{
doc.Database.Audit(true, true);
// doc.Database.Regen(); // Force la régénération des vues
// Sauvegarde
doc.Database.Save();
}
catch (System.Exception ee)
{
CGV.RecordingException(ee, "SaveDoc", false);
}
}
if (!ok)
{
try
{
using (DocumentLock docLock = doc.LockDocument())
{
// Sauvegarder toutes les modifications
doc.Database.SaveAs(doc.Name, DwgVersion.Current); // Si possible
ok = true;
}
}
catch (System.Exception ee)
{
CGV.RecordingException(ee, "SaveDoc", false);
}
}
if (!ok)
{
string originalFilePath = doc.Name;
string tempFilePath = originalFilePath + ".tmp";
try
{
using (DocumentLock docLock = doc.LockDocument())
{
doc.Database.Audit(true, true);
// Sauvegarder toutes les modifications
doc.Database.SaveAs(tempFilePath, DwgVersion.Current);
doc.Database.CloseInput(true);
//doc.Database.SaveAs(doc.Name, DwgVersion.Current); // Si possible
if (File.Exists(originalFilePath))
{
File.Delete(originalFilePath);
}
File.Move(tempFilePath, originalFilePath);
// Renommer le fichier temporaire en fichier original
ok = true;
}
}
catch (System.Exception ee)
{
CGV.RecordingException(ee, "SaveDoc", false);
}
}
}