-4

I open a file in this way and that works fine:

var openFileDialog = new OpenFileDialog;

if (openFileDialog.ShowDialog().GetValueOrDefault())
{
    Browser.FileDoc = File.ReadAllText(openFileDialog.FileName);
}

Now, I want to get the path and pass it to another class. How can I do that?

Stampy
  • 456
  • 7
  • 27

1 Answers1

8

you can use the below menioned code.

OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == true)
{
string filePath = ofd.FileName;
Class2 c=new Class2(filePath);
}

Suppose your another Class is Class2 then

public class Class2
{
string Path=String.Empty;
 public Class2(string _Path)
  {
    Path=_Path;
   }
}
Dhaval Patel
  • 7,471
  • 6
  • 37
  • 70
  • I propose this : `public class Class2 { string _path=String.Empty; public Class2(string p) { Path=p; } public Path{get{return _path;}{set _path=value;}} }` – angel Jun 03 '14 at 12:46