Below code shows the procedure to detach the missing external reference files from a side database
[CommandMethod("DetachXref")] public void detach_xref() { Document Doc = Application.DocumentManager.MdiActiveDocument; Editor ed = Doc.Editor; string mainDrawingFile = @"C:\xref\RectHost.dwg"; using(Database db = new Database(false, false)) { try { db.ReadDwgFile(mainDrawingFile, System.IO.FileShare.ReadWrite, false, ""); } catch (System.Exception) { ed.WriteMessage("\nUnable to read the drawingfile."); return; } bool saveRequired = false; db.ResolveXrefs(true, false); using (Transaction tr = db.TransactionManager.StartTransaction()) { XrefGraph xg = db.GetHostDwgXrefGraph(true); int xrefcount = xg.NumNodes; for (int j = 0; j < xrefcount; j++) { XrefGraphNode xrNode = xg.GetXrefNode(j); String nodeName = xrNode.Name; if (xrNode.XrefStatus == XrefStatus.FileNotFound) { ObjectId detachid = xrNode.BlockTableRecordId; db.DetachXref(detachid); saveRequired = true; ed.WriteMessage("\nDetached successfully"); break; } } tr.Commit(); } if (saveRequired) db.SaveAs(mainDrawingFile, DwgVersion.Current); } }