You are doing it very wrong: your Form2 shouldn't know that Form1 even exists, but less what properties or fields it has.
As soon as I see the keywords
public static
it's obvious you are going wrong - you shouldn't need to be using
static
variables in code this simple, and you shouldn't make fields or controls
public
at all!
Start by reading this:
Transferring information between two forms, Part 1: Parent to Child[
^]
Form1 is your Parent, Form2 is your Child.
Then create the property in Form2 and set it when you create the instance. Now your forms are "decoupled" so only the Parent needs to know anything about the Child.
Then fix your
null
problem - and that's simple as well:
FolderPath = Path.GetDirectoryName(folder.SelectedPath);
Path.GetDirectoryName
expects a path to a file, not a folder - and it returns the folder that file is in. So when you pass it a folder instead of a file, it "strips out" the final folder name:
C:\docs\today
becomes
C:\docs
C:\docs
becomes
C:
C:\
becomes
null
The
SelectedPath
property of the
FolderBrowserDialog
is already a folder, not a file - you don't need to get a folder name from that!