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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:01:50+00:00 2026-06-13T02:01:50+00:00

i got a file that is store in my appliction directory, and he got

  • 0

i got a file that is store in my appliction directory, and he got some site list.
i dont have any problem reading it, but when i want to write to it, i get

System.ArgumentException: Stream is not writeable

this is how i accsess the file:

  FileStream theTextFileStream = new FileStream(Environment.CurrentDirectory + "/fourmlinks.txt",FileMode.OpenOrCreate);

and this is the function that throw me the expection:

public static void WriteNewTextToFile(string text, FileStream theFile)
    {
        string fileText = GetAllTextFromFile(theFile);
        ArrayList fileLIst = populateListFromText(fileText);

        using (StreamWriter fileWriter = new StreamWriter(theFile))
        {
            fileWriter.Write(String.Empty);
            for (int i = 0; i < fileLIst.Count; i++)
            {
                fileWriter.WriteLine(fileLIst[i].ToString());        
            }
        }
    }

the function read the old and new text and add it to an arry. then i clean the file from every thing, and rewriting it with the old and new data from the arry i made.

i dont know if that will help but here is the file proprites:

Build Action: None
Copy To Out Put Directory: Copy always

why i cant rewrite the file?

this is the function i use to read the file content:

public static string GetAllTextFromFile(FileStream theFile)
    {
        string fileText = "";

        using (theFile)
        {
            using (StreamReader stream = new StreamReader(theFile))
            {
                string currentLine = "";
                while ((currentLine = stream.ReadLine()) != null)
                {
                    fileText += currentLine + "\n";
                }

            }
        }

        return fileText;

    }
  • 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-13T02:01:51+00:00Added an answer on June 13, 2026 at 2:01 am

    You have to use Read/Write file access as third parameter –

    FileStream theTextFileStream = new FileStream(Environment.CurrentDirectory + "/fourmlinks.txt",FileMode.OpenOrCreate, FileAccess.ReadWrite
    );
    

    Important – Remove using(theFile) statement:

    public static string GetAllTextFromFile(FileStream theFile)
    {
            string fileText = "";
    
            using (StreamReader stream = new StreamReader(theFile))
            {
                string currentLine = "";
                while ((currentLine = stream.ReadLine()) != null)
                {
                    fileText += currentLine + "\n";
                }
    
            }
    
    
        return fileText;
    
    }
    

    Do not use using construct in your case as it will close the underlying stream as in your case you have to manually open and close stream objects.

    This will allow you to write in the file as well.

    For more information refer following links –

    • FileStream Constructor
    • FileAccess Enumeration
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a source code file that started as a copy of some sample
I have a C# app that creates a settings file for itself to store
I've got some Java Applet that I'd like to use to upload file/files to
I've got a WCF service that acts as a file store. Consuming applications running
I've got a CSV file that I'm processing using the opencsv library. So I
I've got a .js file that has this function in it: function showDialog(divID) {
I've got a file (possibly binary) that contains mostly non-printable ASCII characters as the
I've got a multi line text file that I want to use to create
I've got a particular FLV (VP6/LAME) file that is 400 x 171 pixels as
I've got one really big .java class file that has a lot of members.

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.