GNC
GNC

Reputation:

How to get a file path in a class?

I have this Xml file that i browse from my HDD into my C# program. Now the nodes of this Xml doc get displayed in a tree view in my winform. All my logic is in the winform right now. There are three methods:

  1. To load the Xml doc in memory.
  2. Add nodes to tree which is called by the previous method in point 1.
  3. And event that works when i click on any node to find its attributes.

Rest, i have various buttons like browse, expand tree, clear. all are in the winform. My browse button click event is also in the winform class which is obvious.

Now what i have to do it i have to make a separate class for business logic that includes the method in point 1 and point 2. Rest remains in the winform class. this new class is in the same project. Now the project has two classes - 1 is winforms and the other is that i made to store my business logic so as to keeping frontend class free from business logic.

I cannot do that by making use of objects but i have to make use of giving file path in the class that has the logic. so that, that class knows the file path. Do you have any idea how can i do it?

Please tell me the syntax as i am a newbie.

Upvotes: 0

Views: 461

Answers (1)

Daniel Schaffer
Daniel Schaffer

Reputation: 57862

I believe you're looking for the OpenFileDialog component, if you want the user to be able to specify the path of the file.

If not, then just pass the path in as a parameter in your business class logic:

public class MyBusinessLogic {
   public MyBusinessLogic(String filePath) {
      this.FilePath = filePath;
   }
   public String FilePath { get; private set; }
   public void Process() {
      // whatever you do here
   }
}

Upvotes: 1

Related Questions