This article introduces a few easily overlooked but important method functions in ASP.NET

  • 2020-05-05 11:04:42
  • OfStack

Let me introduce some methods of Path class in NET:

1.   Path.combine(string, string)
        returns a path according to the given two paths.
        e.g.
          string CompletePath = System.IO.Path.Combine(@"c:\MyApp", @"Images\skyline.jpg");
      will return a full path c:\MyApp\Images\ skyline.jpg
      either has the end of "\" in the first parameter or not.

2. Path.GetExtension(string)
      returns the extension for the given file path. For example,
        string FileExtention = System.IO.Path.GetExtention(@"C:\MyApp\Images\skyline.jpg");
      will return "jpg"

3. Path.GetFileName(string)
      gives the full path to the file name and returns the file name (including the extension). For example,
        string fileName = System.IO.Path.GetFileName(@"c:\MyApp\Images\skyline.jpg");
      will return "skyline.jpg "

 


Related articles: