Visual Studio C#: File path error

VAer-4038 766 Reputation points
2020-12-31T13:45:31.903+00:00

I have a class GlobalVariables.cs, I have code public static string InstructionFilePath {get; set;}

Now the code for file path does not work (not able to build solution). If I don't use the variable and use file path directly in Process.Start, it will work.

But my question is: How to write the file path correctly for the variable?

It does not seem it serve as the purpose of global variable. Now I have the code GlobalVariables.InstructionFilePath = "C\User\QR\Documents\Instruction.pdf" within one form. If I use the same file path in a different form, should I need to write GlobalVariables.InstructionFilePath = "C\User\QR\Documents\Instruction.pdf" again?

Is it a way to write GlobalVariables.InstructionFilePath = "C\User\QR\Documents\Instruction.pdf" outside a form? But it seems it is also wrong to write it in GlobalVariables.cs

The reason is: If I use C\User\QR\Documents\Instruction.pdf in multiple forms, and I would like to set to it as GlobalVariables.InstructionFilePath, so that I only need to update it in one place (if the file has moved).

Thanks.

52592-filepatherror.jpg

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,011 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 85,881 Reputation points
    2020-12-31T14:14:56.343+00:00

    Double the "\" or add @ before the string...


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.