Click here to Skip to main content
15,918,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

My attachment name is : TimeSheet URD V1.0.doc

i want to split it as "TimeSheet URD V1.0" and "doc".

I used str[] strWords=str.Split('.'). This code gave me only "TimeSheet URD V1".

How can i achieve to get the full file name without extension?

Please help me to resolve this issue.

Thanks.
Posted

1.
C#
String returnValue = Path.GetFileNameWithoutExtension(path);


2.
C#
if (this.openFileDialog1.ShowDialog() == DialogResult.OK) 
{
  String returnValue = openFileDialog1.SafeFileName;
}


3.

use lastindexof(".") ,not indexof (".")

C#
strFilePaht.Substring(path.LastIndexOf("\\") + 1, path.Length - 1 - path.LastIndexOf("\\"));
strFilePaht.Substring(path.LastIndexOf("."), path.Length - path.LastIndexOf("."));
 
Share this answer
 
v3
Hi, Use this:

C#
string s = "TimeSheet URD V1.0.doc";
int i = s.LastIndexOf('.');
string lhs = i < 0 ? s : s.Substring(0, i),
    rhs = i < 0 ? "" : s.Substring(i + 1);


Got this source from:

Best-way-to-break-a-string-on-the-last-dot-on-c-sharp

and it works!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900