user72731
user72731

Reputation: 7

I want to know the usage of filepath

I have made a project in which i have a business logic and a GUI. Now i have to separate them in the same project. where business logic is in different class. In my project there is a file that needs to be loaded from memory. Then manipulations in that file is done in the business logic class and results displayed in the winform. Now i want to give the file path in the business logic class so that any xml file i browse gets displayed on the winform. What is the syntax to do that i.e. to give the file path. Something like String filename= (what after this). so that the file gets opened in the winform.

Upvotes: 0

Views: 139

Answers (1)

user1228
user1228

Reputation:

As I understand it, you get a file path from the UI and are wondering how to best pass this path to your business logic classes.

A string is a very common and acceptable way to pass a file path from one class to another.

FxCop may complain and request you use a Uri. I think that's a bit of overkill, and the Uri class can be confusing. I'd suggest skipping it.

Another way is to pass a FileInfo. Your UI gets the file path from the user, creates a FileInfo, and determines from this if the file exists and if its available to the user. If it isn't, the UI reports back to the user and waits for input. If it is, just pass the FileInfo to your business logic. There it can be used to construct a stream that an XmlReader can consume.

Of the three I'd say 3 sounds the best. The first is done more often, however.

Upvotes: 1

Related Questions