1

I have a varaible UrlList which holds the Directory of which is supposed to be entered in a Text box, what I want though, is to check whether the given Directory file is a text file or not, so the User gets prompted to either Cancel his Actions or give in a correct file.

Code Snippet:

public static string UrlList = @"C:\Users\gbbb\Desktop\Url.txt";
private string[] _UrlRows;

and this is the method i sorta started, and then realised i Need help for

private void LoadUrls()
{   
    if (UrlList == System.TEXT-FILE)
        _Urlrows = System.IO.File.ReadAllLines(@UrlList);
}
SatA
  • 537
  • 1
  • 6
  • 15
gbbb
  • 203
  • 3
  • 5
  • 14

2 Answers2

1

you can use Path.GetExtension method

if(System.IO.Path.GetExtension(path).Equals(".txt",StringComparison.OrdinalIgnoreCase))
{

}
Damith
  • 62,401
  • 13
  • 102
  • 153
1

If I understand you clearly, you just need to use Path.GetExtension method.

Returns the extension of the specified path string.

string ext = Path.GetExtension(@"C:\Users\gbbb\Desktop\Url.txt");

if(ext == ".txt")
{
   string[] readText = File.ReadAllLines(@"C:\Users\gbbb\Desktop\Url.txt");
}
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364