filenames / extensions with file uploads

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
 
M

Martin Dechev

Hi, Lauchlan M,

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

Greetings
Martin
 
E

Eric Lawrence [MSFT]

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.
 
L

Lauchlan M

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

That worked ok.

Ta

Lauchlan M
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top