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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:39:08+00:00 2026-06-05T22:39:08+00:00

I have a Class CButtonCreate without get & set Methode. But i wanna use

  • 0

I have a Class CButtonCreate without get & set Methode. But i wanna use the Attribute “string newFileName” from the Class CButtonCreate in a other Class thats Class WriteToFile. How can use the Attribute newFileName in the Class WriteToFile?

class CButtonCreate
{
    // Create a Folder && SubFolder from the tbProject
    public void CreateFolder(string MyFolderName, string Mytbs, string MytbRevision, string MyTestSystem)
    {
        // Open the Directory path
        string activeDir = @"Y:\temp";

        //Combine the current active folder with the tbProject
        string newPath = Path.Combine(activeDir, MyFolderName);

        // Create a folder in the active Directory
        Directory.CreateDirectory(newPath);

        // Create a new SubFolder name. This example generates a random string. "tbs"
        string newSubPath = Path.Combine(newPath, Mytbs);

        //Create a new Subfolder under the current active folder
        Directory.CreateDirectory(newSubPath);

        // Create a new file name.
        string newFileName = "Project_" + MyFolderName + "_" + MytbR + ".txt";

        // Combine the new file name with the path
        newPath = System.IO.Path.Combine(newPath, newFileName);

        if (!System.IO.File.Exists(newPath))
        {
            using (System.IO.FileStream fs = System.IO.File.Create(newPath))
            {
               // Call the Function WriteInFile
            }
        }
    }

class WriteToFile
{
    public void WriteInFile(string MyFolderName, string MytextBox, string MytbR, string MycbTest)
    {
        CButtonCreate myFile = new CButtonCreate();
        StreamWriter sw = new StreamWriter(newFileName);
    }
}
  • 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-05T22:39:11+00:00Added an answer on June 5, 2026 at 10:39 pm

    Your WriteInFile method needs to take the newFileName value as an argument to the method, such as:

    class WriteToFile
    {
        public void WriteInFile(string newFileName, string MyFolderName, string MytextBox, string MytbR, string MycbTest)
        {
            CButtonCreate myFile = new CButtonCreate();
            StreamWriter sw = new StreamWriter(newFileName);
        }
    }
    

    Then, from CButtonCreate.CreateFolder you would call it like this:

    WriteToFile w = new WriteToFile();
    w.WriteInFile(newFileName, ...);
    

    Or, if you’d rather, you could pass the value to a parameter in the WriteToFile constructor, such as:

    class WriteToFile
    {
        public WriteToFile(string newFileName)
        {
            _newFileName = newFileName;
        }
    
        private string _newFileName;
    
        public void WriteInFile(string MyFolderName, string MytextBox, string MytbR, string MycbTest)
        {
            CButtonCreate myFile = new CButtonCreate();
            StreamWriter sw = new StreamWriter(_newFileName);
        }
    }
    

    And then, from CButtonCreate.CreateFolder you would call it like this:

    WriteToFile w = new WriteToFile(newFileName);
    w.WriteInFile(...);
    

    There are other ways to do it as well using a property, by passing the CButtonCreate object to the WriteToFile object, or by using static properties, but those two options I gave examples of would seem to be the most likely and best solutions.

    Also, I should mention that you are misusing the term “Attribute”. In .NET languages, attributes are a very specific thing which is entirely different than what you are talking about. Attributes provide a way to “decorate” your code with metadata that describes your code. For instance, there are some attributes that instruct the debugger whether or not to trace into your method or just skip over it while debugging. There are other attributes that instruct the compiler how to properly build your assembly. Attributes are used, for instance, to specify the version numbers for your assemblies.

    I believe the term you meant to use was either “property” or “field”. However, neither of those terms are correct either, because the newFileName variable is currently a local variable to the CreateFolder method. Therefore, there is no way to access it externally from another class, or even from another method within the same class because it’s scope is that CreateFolder method. It only exists while that method is being executed. As soon as that method ends, that string is gone. If, for some reason, you wanted to make it accessible to the whole class, you would need to move it up to the class level and make it a field for the class:

    class CButtonCreate
    {
        private string newFileName;
    
        public void CreateFolder(string MyFolderName, string Mytbs, string MytbRevision, string MyTestSystem)
        {
            ...
        }
    }
    

    Then, if you wanted to make it accessible to other classes, you could create a public get/set property for it.

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

Sidebar

Related Questions

I have class public class Class2 { public string myName { get; set; }
I have class public class Chat { public string Ip { get; set; }
I have class with member functions: typedef std::function<bool (const std::string &)> InsertFunction; bool insertSourceFile(
I have class: public class MyClass { [XmlElement(Date)] public DateTime Date { get; set;
I have: class Foo { int a; int b; std::string s; char d; };
I have class in server side and I want use method of this class
I have class that extends BroadcastReceiver and gets all new sms. When I get
I have class Person: public class Person : INotifyPropertyChanged { private String name =
I have class A and B which inherit from Base. Base has a private
I have class with internal property: internal virtual StateEnum EnrolmentState { get { ..getter

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.