Message 1 of 2
Prevent from opening central file / create detached file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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);
}