Get File Extension in C Sharp

get file extension in c#

Get File Extension in C#

In order to know about extension in c#, this tutorials provide details about Get file extension in c#. Path.GetExtension. Mostly file names have a specific extension. A program may only need to test for one file extension. We question if Path.GetExtension is ideal. We can use this method and also compare its performance to a simpler but custom method.

Public static string GetFileExtension(this string FileNameWithExtension)
{
try
{
return FileNameWithExtension.Substring(FileNameWithExtension.LastIndexOf('.') + 1);
}
catch (Exception)
{
return "";
}
}

get file extension in c#
get file extension in c#

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 “”;
}
}

For reference : Get file extension in c#

how to zip the file using ionic

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.