ObjectARX
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Error efileinternalerror

0 REPLIES 0
Reply
Message 1 of 1
sizy458
74 Views, 0 Replies

Error efileinternalerror

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

    
}

 

 

 

 

Labels (1)
0 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report