Thanks for clarifying that Saikat.
I'm now looking at the alternative workflow by using events as you have suggested. It looks like I can achieve my goal by hooking into the ViewActivated event and then checking if the document in the view is a family. If true I perform my custom steps to establish permissions and if its found the user is not authorized pop up a message and close the document (family editor).
I note that document.close() doesn't work but a work around (and dangers of this approach) is in one of Jeremy's blogs:
http://thebuildingcoder.typepad.com/blog/2010/10/closing-the-active-document-and-why-not-to.html
Despite the dangers of this approach, closing the view is the only way I can think of to interupt the normal flow. So a simplified version of the code by way of example now looks like this:
private void OnViewActivated(object sender, ViewActivatedEventArgs e)
{
if (e.Document.IsFamilyDocument)
{
// custom checks here, AD checks,
// list of protected families, etc
// bool allowEdit = false;
// etc
//-------------------
if (allowEdit == false)
{
TaskDialog.Show("Permission Denied",
"This is a protected family. Please contact xxxx
if you wish to make changes.");
System.Threading.ThreadPool.QueueUserWorkItem(new
System.Threading.WaitCallback(CloseDocProc));
return;
}
}
}
static void CloseDocProc(object stateInfo)
{
try
{
// maybe we need some checks for the right
// document, but this is a simple sample...
System.Windows.Forms.SendKeys.SendWait("^{F4}");
}
catch (Exception ex)
{
Util.ErrorMsg(ex.Message);
}
}