filenames / extensions with file uploads

  • Thread starter Thread starter Lauchlan M
  • Start date Start date
L

Lauchlan M

Hi

I'm doing a file upload and I get

//get the filename
string FullFileNameAndPath = fileDischargeFile.PostedFile.FileName;

This returns the full filepath, eg c:\folder\filename.ext

What I want to do is get the filename (as 'filename.ext') and the extension
(as '.ext') from this full path.

What are the best .net methods/namespaces to use for this?

Thanks

Lauchlan M
 
Hi, Lauchlan M,

You should use the methods Substring and LastIndexOf on the string class.

Greetings
Martin
 
I believe the File and Directory objects have static methods to parse the
string into its components.

--
Thanks,

Eric Lawrence
Program Manager
Assistance and Worldwide Services

This posting is provided "AS IS" with no warranties, and confers no rights.
 
You should use the methods Substring and LastIndexOf on the string class.

That worked ok.

Ta

Lauchlan M
 
Back
Top