Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8281133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:55:38+00:00 2026-06-08T09:55:38+00:00

I am using a FileSystemWatcher to monitor a folder. But when there is some

  • 0

I am using a FileSystemWatcher to monitor a folder. But when there is some event happening in the directory, I don’t know how to search who made a impact on that file. I tried to use EventLog. It just couldn’t work. Is there another way to do it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T09:55:41+00:00Added an answer on June 8, 2026 at 9:55 am

    I cant remember where I found this code but its an alternative to using pInvoke which I think is a bit overkill for this task. Use the FileSystemWatcher to watch the folder and when an event fires you can work out which user made the file change using this code:

    private string GetSpecificFileProperties(string file, params int[] indexes)
    {
        string fileName = Path.GetFileName(file);
        string folderName = Path.GetDirectoryName(file);
        Shell32.Shell shell = new Shell32.Shell();
        Shell32.Folder objFolder;
        objFolder = shell.NameSpace(folderName);
        StringBuilder sb = new StringBuilder();
    
        foreach (Shell32.FolderItem2 item in objFolder.Items())
        {
            if (fileName == item.Name)
            {
                for (int i = 0; i < indexes.Length; i++)
                {
                    sb.Append(objFolder.GetDetailsOf(item, indexes[i]) + ",");
                }
    
                break;
            }
        }
    
        string result = sb.ToString().Trim();
        //Protection for no results causing an exception on the `SubString` method
        if (result.Length == 0)
        {
            return string.Empty;
        }
        return result.Substring(0, result.Length - 1);
    }
    

    Shell32 is a reference to the DLL: Microsoft Shell Controls And Automation – its a COM reference

    Here is some example’s of how you call the method:

    string Type = GetSpecificFileProperties(filePath, 2);
    string ObjectKind = GetSpecificFileProperties(filePath, 11);
    DateTime CreatedDate = Convert.ToDateTime(GetSpecificFileProperties(filePath, 4));
    DateTime LastModifiedDate = Convert.ToDateTime(GetSpecificFileProperties(filePath, 3));
    DateTime LastAccessDate = Convert.ToDateTime(GetSpecificFileProperties(filePath, 5));
    string LastUser = GetSpecificFileProperties(filePath, 10);
    string ComputerName = GetSpecificFileProperties(filePath, 53);
    string FileSize = GetSpecificFileProperties(filePath, 1);
    

    Or get multiple comma separated properties together:

    string SizeTypeAndLastModDate = GetSpecificFileProperties(filePath, new int[] {1, 2, 3});
    

    Note: This solution has been tested on Windows 7 and Windows 10. It wont work unless running in a STA as per Exception when using Shell32 to get File extended properties and you will see the following error:

    Unable to cast COM object of type ‘Shell32.ShellClass’ to interface type ‘Shell32.IShellDispatch6’

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

while the application is running i'm using FileSystemWatcher to monitor the folder. But what
I'm monitoring a folder using FileSystemWatcher. If I download a file into there, how
I'm working on writing a FileSystemWatcher using Mono but for some reason the callback
I want to monitor a folder located on another computer using the FileSystemWatcher .
I'm trying to monitor a folder using C# and FileSystemWatcher. everything works well, except
I am looking to monitor a folder for create events using the FileSystemWatcher in
Is there a way to monitor (e.g. creation) alternate data streams using FileSystemWatcher? Or,
I'm using FileSystemWatcher to monitor folder A. if a file is created or copied
We have several .NET applications that monitor a directory for new files, using FileSystemWatcher.
I have an application that is using FileSystemWatcher to monitor a folder for changes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.