| Article | 70002828 |
| Type | HowTo |
| Product | Engine |
| Date Added | 1/21/2026 12:00:00 AM |
| Fixed | 11.5.20 (1/21/2026 12:00:00 AM) |
| Submitted by | Yiannis Makarounis |
Summary
Sometimes the AddFromFile method fails (like a file is not present on disk or network or no have rights top read the file) but the GenericError doesn't fire for such cases. What can I do?
Solution
Try a code like:
.....
.... Where docfrom is a vdDocument like vdFramedControl1.BaseControl.ActiveDocument in your form.
bool redefineBlock = true;
string FileName = @"//SomeNetworkPath/test/11.vdml";
vdBlock blk = AddFromFileX(docfrom, FileName, redefineBlock);
......
public vdBlock AddFromFileX(vdDocument Document, string FileName, bool redefine)
{
string blockname = VectorDraw.Professional.Utilities.vdGlobals.GetFileNameWithoutExtension(FileName);
vdBlock ret = Document.Blocks.FindName(blockname);// check if exists
if (ret != null && ret.Deleted) redefine = true;
if (ret != null && !redefine) return ret;// returns the block that already exists with this name
string supportpath = Document.SupportPath;
Document.SupportPath += (";" + VectorDraw.Professional.Utilities.vdGlobals.GetDirectoryName(FileName));
vdDocumentComponent docComp = new vdDocumentComponent(); //Utility component and document to open the file
// event to check if and what error happend loading the drawing
docComp.Document.GenericError += new vdDocument.GenericErrorEventHandler(doc_GenericError);
vdDocument doc = docComp.Document;
doc.Openflags |= Document.TopMostDocumet.Openflags;
bool success = doc.Open(FileName);
try
{
if (success)
{
ret = Document.Blocks.AddFromDocument(blockname, doc, redefine); // add it to the master document
}
}
catch { }
docComp.Document.GenericError -= new vdDocument.GenericErrorEventHandler(doc_GenericError);// not needed any more
Document.SupportPath = supportpath;
doc.InternalSetOwner(null);
doc.Dispose();
return ret;// returns null or the block added from the file
}
void doc_GenericError(object sender, string Membername, string errormessage)
{// here will show the error if the Open didn't worked
MessageBox.Show("docComp: " + errormessage + " " + Membername);
}
