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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Kunal VaishyaPosted Dec 16, 2014, 5:04 AM
{
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 VaishyaPosted Dec 16, 2014, 3:51 AM
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;
}
Khargesh RajputPosted Dec 16, 2014, 3:14 AM
string myString = (text.Length > 8) ? text.Substring(text.Length - 9, 9) : text;
Response.Write(myString);
Manish Kumar ChoudharyPosted Dec 16, 2014, 2:59 AM
directoryName = Path.GetDirectoryName(filePath);filePath, directoryName);filePath = directoryName;Najim MullaPosted Dec 16, 2014, 2:48 AM
Manish Kumar ChoudharyPosted Dec 16, 2014, 2:41 AM
Hi Najim Mulla,