File change to readonly

Dani_S 3,786 Reputation points
2024-09-29T17:00:18.9866667+00:00

Hi, i load files to our website. When i open one of the file during the loading.I get the file caught by another process.Does making the files as readonly will solved the problem. If not can you give other suggestion. How to set file to readonly and what permission i need?Thanks

Windows
Windows
A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
5,376 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,902 questions
{count} votes

Accepted answer
  1. Jiale Xue - MSFT 44,926 Reputation points Microsoft Vendor
    2024-09-30T08:31:41.9133333+00:00

    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.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.