Hi @Dani_S , Welcome to Microsoft Q&A,
Marking a file as "read-only" may not completely solve the "file caught by another process" problem.
The "caught by another process" error usually occurs when one process has exclusive access to a file (for example, during a file upload or modification), thereby preventing other processes from accessing it. Marking a file as read-only prevents modification, but does not prevent another process from opening the file if the first process still holds the exclusive lock (for example, an upload process that has not yet completed writing the file).
How do I set a file to readonly, and what permissions do I need?
To set a file to readonly in C#:
FileInfo fileInfo = new FileInfo("path_to_your_file");
fileInfo.IsReadOnly = true;
To set a file to readonly manually (via Windows File Explorer):
- Right-click on the file → Properties → Check "Read-only" under Properties.
Setting a file to read-only does not require special permissions, just the ability to modify the file attributes. - The user who owns the file or someone with administrative privileges can set a file to read-only.
I don't understand what you are trying to do specifically. Use a file access mode that allows shared read access. For example, when opening the file in your code, make sure you allow sharing ("FileShare.Read"), other processes can still read the file while it is being uploaded or used.
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.