C:\Abc\file.text
how can splite ("\")
to get only file name as like file.text
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Manish Kumar ChoudharyRank #339 · 7.4K reputationPosted Dec 15, 2014, 9:41 PM EST
Hi Najim Mulla,
Najim MullaRank #2,088 · 689 reputationPosted Dec 15, 2014, 9:48 PM EST
Manish Kumar ChoudharyRank #339 · 7.4K reputationPosted Dec 15, 2014, 9:59 PM EST
Khargesh RajputRank #616 · 3.9K reputationPosted Dec 15, 2014, 10:14 PM EST
string myString = (text.Length > 8) ? text.Substring(text.Length - 9, 9) : text;
Response.Write(myString);
Kunal VaishyaRank #990 · 2K reputationPosted Dec 15, 2014, 10:51 PM EST
Example:
protected void Page_Load(object sender, EventArgs e)
{
string sFile = GetFileNameWithExt(@"C:\Abc\file.text");
}
public string GetFileNameWithExt(String strFilePath)
{
string[] FileStpit1 = strFilePath.Split(Convert.ToChar(@"\"));
string sFileName = FileStpit1[Length - 1];
return sFileName;
}
Kunal VaishyaRank #990 · 2K reputationPosted Dec 16, 2014, 12:04 AM EST
{
string sFile = GetFileNameWithExt(@"C:\Abc\file.text");
}
public string GetFileNameWithExt(String strFilePath)
{
string[] FileStpit1 = strFilePath.Split(Convert.ToChar(@"\"));
string sFileName = FileStpit1[Length - 1];
return sFileName;
}