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 6784733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:01:58+00:00 2026-05-26T17:01:58+00:00

What I want to do is overwrite a read-only file. With a read/write file.

  • 0

What I want to do is overwrite a read-only file. With a read/write file.

With read/write files if I use File.Open(file, FileMode.Create) then if the file exists then it is deleted and a new one is created. (Although I suspect that if it exists then it just opens the file and removes the contents, which is why it is unable to cope with files it encounters as read/write).

I have tried with different FileAccess enums, but none of them seem to help me (I keep getting a UnauthorizedAccessException).

The work around is that I just set the file as read/write before I try to File.Open and make a new file, is this the only way to do this?

Thanks

  • 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-05-26T17:01:59+00:00Added an answer on May 26, 2026 at 5:01 pm

    Consider the purpose of ReadOnly. It’s to stop alterations to the file. What you’re trying to do, is alter the file (in this case by overwriting it).

    What I would imagine you would need to do, is set the file attribute:

    File.SetAttributes(filePath, FileAttributes.Normal);
    

    Before you write to the file.

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

Sidebar

Related Questions

I want to parse, process and then overwrite only 1 specific column in a
I have some read-only data that I want to initialise and then re-initialise periodically
I want to declare three properties in my MSBuild file and overwrite one property
I tried to manipulate the __mro__ but it it read-only The use case is
I want to read (only) records from data/data/com.android.providers.telephony/databases/mmssms.db (I know no official API, etc.
Given two integers X and Y, I want to overwrite bits at position P
I'm deploying a Wordpress blog, but I don't want to overwrite the current site
I have some simple text file. I am trying to read that file contents
I'm new to C++ and trying to implement a turtle emulator that will read
I have read various blogs about Serialization and the use of serialVersionUID. Most of

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.