# V3039. Consider inspecting the 'Foo' function call. Defining an absolute path to the file or directory is considered a poor style.

The analyzer has detected a possible error in a call to a function intended for file handling. The error has to do with an absolute path to a file or directory being passed to the function as one of the arguments. Passing absolute paths as arguments can be dangerous since such paths may not exist on the user's computer.

Consider the following example:

    String[] file = File.ReadAllLines(
      @"C:\Program Files\MyProgram\file.txt");

A better solution is to get the path to the file based on certain conditions.

This is what the fixed version of the code should look like:

    String appPath = Path.GetDirectoryName(
                     Assembly.GetExecutingAssembly().Location);
    String[] fileContent = File.ReadAllLines(
                           Path.Combine(appPath, "file.txt"));

In this code, the file will be looked up in the application's directory.

This diagnostic is classified as:

CWE-39