Get fileExtension/FileName/GetNewFileNameGUID from file in .net

 public static string GetFileExtension(this string FileNameWithExtension)
{
try
{
return FileNameWithExtension.Substring(FileNameWithExtension.LastIndexOf(‘.’) + 1);
}
catch (Exception)
{
return “”;
}
}

//Get File Name when file with extension.

public static string GetFileName(this string FileNameWithExtension)
{
try
{
return FileNameWithExtension.Substring(0, FileNameWithExtension.LastIndexOf(‘.’));
}
catch (Exception)
{
return “”;
}
}

 

public static string GetNewFileNameGUID(this string FileNameWithExtension)
{
try
{
return (Guid.NewGuid().ToString() + “.” + FileNameWithExtension.GetFileExtension());
}
catch (Exception)
{
return “”;
}
}

SHARE THIS

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.