Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Rachel 1 post 71 karma points
    Oct 23, 2023 @ 12:25
    Rachel
    0

    pdf file properties on MediaSavingNotification

    I need to check when uploading PDF files to the media folder whether the file is, let's say, by checking the "author" file property. This is the code, I can't get the "author" property:

    public class FileUploadEventHandler : INotificationHandler<MediaSavingNotification>
        {
            public void Handle(MediaSavingNotification notificatin)
            { 
                    foreach (var media in notificatin.SavedEntities)
                    {
                    if (media.HasProperty("author"))
                        {
                            // Get the value of the property
                            var propertyValue = media.GetValue<string>("author");
    
                            // Perform your accessibility check here
                            if (!IsFileAccessible(propertyValue))
                            {
                            notificatin.CancelOperation(new EventMessage("error",
                                "The file is not accessible",
                                EventMessageType.Error));
                            // File is not accessible, prevent saving the media item
                          }
                        }                              
                    }
                }
            private bool IsFileAccessible(string propertyValue)
            {
                // Implement your logic to check if the file is accessible
                // Return true if the file is accessible, otherwise return false
                // You can check permissions, file existence, file size, etc.
                // Based on your requirements
    
                // Example: Check if the property value is empty or null
                return !string.IsNullOrEmpty(propertyValue);
            }
    
    
        }
    
Please Sign in or register to post replies

Write your reply to:

Draft