File change to readonly

Dani_S 5,581 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 for business | Windows Client for IT Pros | User experience | Other
Developer technologies | C#
Developer technologies | 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.
{count} votes

Answer accepted by question author
  1. Anonymous
    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' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.