Instant control over file and folder operations in Windows and .NET applications

OnCanFileBeDeletedC event/delegate/callback


Pascal    C++ (Lib)    C++ (VCL)    C++ (.NET)    C#    VB.NET   

CallbackFilter     See also    


This callback is called when the OS needs to query possibility to delete the file or directory.


    property OnCanFileBeDeletedC : TCbFltCanFileBeDeletedEventC;
    TCbFltCanFileBeDeletedEventC = procedure(Sender : TObject; FileName: TCBString; var DeleteFile: Boolean; var UserContext: pointer; var ProcessRequest: boolean) of object;
    type TCBString = {$ifdef UNICODE}UnicodeString{$else}WideString{$endif};

[C++ (Lib)]
    typedef void (*CbFltCanFileBeDeletedEventC)(CallbackFilter* Sender, LPWSTR FileName, LPBOOL DeleteFile, PVOID* UserContext, LPBOOL ProcessRequest);

[C++ (VCL)]
    typedef void __fastcall (__closure *TCbFltCanFileBeDeletedEventC)(System::TObject* Sender, TCBString FileName, bool &DeleteFile, void * UserContext, bool &ProcessRequest);
    #ifdef UNICODE
    typedef UnicodeString TCBString;
    typedef WideString TCBString;

[C++ (.NET)]
    public delegate void CbFltCanFileBeDeletedEventC(CallbackFilter^ Sender, String^ FileName, bool% DeleteFile, IntPtr% UserContext, bool% ProcessRequest);

    delegate void CbFltCanFileBeDeletedEventC(CallbackFilter Sender, string FileName, ref bool DeleteFile, ref IntPtr UserContext, ref bool ProcessRequest);

    Delegate Sub CbFltCanFileBeDeletedEventC(ByVal Sender As CallbackFilter, ByVal FileName As String, ByRef DeleteFile, ByRef UserContext As IntPtr, ByRef ProcessRequest As Boolean)


  • Sender - reference to the class that called the delegate/event handler
  • FileName - name of the file
  • DeleteFile - set this parameter to allow or prevent deletion of the file
  • UserContext - the placeholder for the application-defined data
  • ProcessRequest - specifies, whether the request must be passed further to the underlying filters and the file system


This callback is called when the OS needs to check if the file or directory can be deleted. If you set DeleteFile to false, doing this will prevent deletion but will not report that deletion was not performed to the OS. And the caller will think that the file has been deleted. If you want to return an error, thrown ECbFltError instead with the appropriate error code (eg. ACCESS_DENIED).

Error handling

See Error handling topic for detailed information about how to report errors, which occur in the event handlers, back to CallbackFilter.

See also

OnPostCanFileBeDeletedC     OnCanFileBeDeletedN    

Back to top