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

  • Home
  • SEARCH
  • 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 494965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:32:54+00:00 2026-05-13T05:32:54+00:00

Just got some errors in code, which says the file is being used. What

  • 0

Just got some errors in code, which says the file is being used.
What I need to achieve is add first part of encrypted data in file and then add second part of of evcrypted data in the same file. This file need to be decrypted later. I am pretty new to this field. Many thanks.

    Class3 cs3;
    StreamWriter sWriter;

    private void Add_text_Part_One()
    {
        Rijndael RijndaelAlg = Rijndael.Create();
        // Create a string to encrypt.
        string sData = "Here is some data to encrypt.";
        string FileName = @"C:\CText.txt";

        cs3 = new Class3(sData, FileName, RijndaelAlg.Key, RijndaelAlg.IV);
        sWriter = new StreamWriter(cs3.getCS());
        sWriter.WriteLine(sData);
        sWriter.Close();
    }

    private void Add_text_Part_Two()
    {
        string sData = "Here is some more data to encrypt.";
        sWriter.WriteLine(sData);
        sWriter.Close();
    }
class Class3
{
    FileStream fStream;
    Rijndael RijndaelAlg;
    CryptoStream cStream;
    public Class3(String Data, String FileName, byte[] Key, byte[] IV)
    {
        fStream = File.Open(FileName, FileMode.Append);
        RijndaelAlg = Rijndael.Create();
        cStream = new CryptoStream(fStream, RijndaelAlg.CreateEncryptor(Key, IV), CryptoStreamMode.Write); 
    }
    public CryptoStream getCS()
    {
        return cStream;
    }

    public string getRes()
    {
        StreamReader sReader = new StreamReader(cStream);
        string val = null;
        val = sReader.ReadLine();
        return val;
    }     
  • 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-13T05:32:54+00:00Added an answer on May 13, 2026 at 5:32 am

    in the constructor of Class3 you call File.Open() and assign the resulting FileStream to fstream. This fstream object is never closed, so the file remains open. You are going to have to close the fstream (prefereably implement IDisposable and use Class3 within a using block)

    Edit: Sorry, I think I’m kind of losing it here. I don’t believe the above is right, however, you are closing the StreamWriter, and then trying to write to it again in part II, when it is closed, might want to take a look at that.

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

Sidebar

Related Questions

I just got Delphi 2009 and have previously read some articles about modifications that
I just got a dedicated server from a hosting company, and for some reason,
I am just starting with C++ and got some problems in understanding how the
We just added an autoupdater in our software and got some bug report saying
Delphi 2009, among some cool stuff, has also just got Anonymous methods. I've seen
I've got a simple asmx web service that just needs to log some information
We've got several Flex projects, one of which has just been refactored. I'm wondering
I switched from Visual Studio to Code::Blocks yesterday, and just had some strange compiler
Just got a request from my boss for an application I'm working on. Basically
Just got a question about generics, why doesn't this compile when using a generic

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.