bandeee
bandeee

Reputation: 81

How do I get just the name of the file from the path?

I'm saving something from winform to a file, with SaveFileDialog (svf), and I would like to use the name of the file, after saving, how can I do it?

sfd.FileName; 

It's not the right way, because it has got the path too... (for example:c:/asd/asd/asd.doc)

Upvotes: 2

Views: 82

Answers (2)

ChrisF
ChrisF

Reputation: 137188

You need to use the various Path methods to split the path into the various components you need.

In this case it's Path.GetFileName

string filename = Path.GetFileName(sfd.FileName);

Upvotes: 3

Andrew Barber
Andrew Barber

Reputation: 40160

You would use Path.GetFileName() to get just the filename.

string fileName = Path.GetFileName(sfd.FileName);

Upvotes: 4

Related Questions