I have tried to change everything according to what the error tells me, as it sometimes says that there is not a file where I intend it to look, then I move it or change the code for it to much but it just decides to not work that time, etc, maybe it is another problem whit the line in it's self, so I'm going to write and explain in more detail after this.
if (Convert.ToInt32(
File.ReadAllText(@"TextFile1.txt")
.Split('\n')[0])
==0)
What I'm trying to do here is accessing and comparing a file that is going to be within the programs files as I'm going to turn it into an application. This exact segment is reading the text file, cutting it before the first new line and seeing if the number it sees is 0 (If so then it's the first time it's run), the file location needs to be relative as its going to be installed in a completely new random computer each time, but I just can get it to work right. If you can help me whit this project I would very much appreciate it.
The Error I'm getting is:
HResult=0x80131537
Mensaje = Input string was not in a correct format.
Origen = System.Private.CoreLib
Seguimiento de la pila:
at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, TypeCode type)
at System.Number.ParseInt32(ReadOnlySpan`1 value, NumberStyles styles, NumberFormatInfo info)
at System.Convert.ToInt32(String value)
at Web.Program.Main(String[] args) in C:\Users\<MyUser>\source\repos\Web\Web\Program.cs:line 37
I don't know if it is because of the path, because of any other issues because of the format of an estracted string from a file (?), please I would like to know what you can tell me or anything I can do.
User contributions licensed under CC BY-SA 3.0