Prevent from opening central file / create detached file

Prevent from opening central file / create detached file

lwlXUTTT
Advocate Advocate
242 Views
1 Reply
Message 1 of 2

Prevent from opening central file / create detached file

lwlXUTTT
Advocate
Advocate

Dear Community,

 

I want to check if user if opening a central file and if so cancel the operation. The check I perfrom OnDocumentOpening event. Everything is working fine, so central file is not opened (check == true) and local files are easily created (check == false). However, my solution also prevents me from creating Detached File from central file (check == true)... Does anyone have an idea how I can adjust code below, so also Detached file operation can be performed (so check = false)?

 

#raising check on DocumentOpening Event

private void OnDocumentOpening(object sender, DocumentOpeningEventArgs e)
{
   string docPathName = e.PathName;

   if (IsOpenedAsCentral(docPathName))
      e.Cancel();
}

 

#check implementation

 

public static bool IsOpenedAsCentral(string pathName)
{
   BasicFileInfo info = BasicFileInfo.Extract(pathName);
   if (info == null) return false;

   string fileName = Path.GetFileName(pathName);
   string centralFileName = string.Empty;

   if (info.CentralPath.Length > 0)
      centralFileName = Path.GetFileName(info.CentralPath);

   return centralFileName.Equals(fileName);
}

 

 

 

0 Likes
243 Views
1 Reply
Reply (1)
Message 2 of 2

jeremy_tammik
Alumni
Alumni

I do not see how this differentiation could be made based on the code snippet you share. Maybe you can find additional sources of information to obtain additional information to help tell the difference. For instance, have you looked at the contents of the journal file, or looked at other events? Here is one interesting sample to detect command ended:

  

https://thebuildingcoder.typepad.com/blog/2020/01/torsion-tools-command-event-and-info-in-da4r.html#...

  

I guess you are more interested in command started...

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes