If your file is called linksXML then it will also need a path and an extension so that line should read something like
if (!File.Exists("c:\myfolder\linksXML,xml"))
The only way the code you have could work is if you have a class level variable called
linksXML
to which you have assigned a value in code that you have not shared
Edit after OP Comment:
By adding the XML file to your solution you are able to edit the file within Visual Studio. That does not mean you can reference it with just that part of it's name.
Look at the documentation for
File.Exists(String) Method (System.IO) | Microsoft Docs[
^]. It is expecting a string. The fact that Visual Studio is showing a red line under
linksXML
means that it does not know what
linksXML
is.
Either pass a string directly to the File.Exists function OR somewhere you need to declare linksXML as a variable and assign it a value e.g.
string linksXML = "c:\myfolder\linksXML";
There is no declaration for
linksXML
in the code you have shared, so if you have declared a variable it was outside of the method addLink. For such a variable to be in scope it would have to have been declared within the class that contains addLink. See
https://www.pluralsight.com/guides/understanding-scope-and-visibility-in-c[
^] for more detail.
If you are including the XML file in your solution then yes, you still need the path and you will need to take care over which path is used depending on debug or release build - see
How to get the current project path[
^] for more details.