Try another variable:
string aktVerz = Path.GetDirectoryName( Assembly.GetEntryAssembly( ).Location );
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi
I try to save some Data with streamwriter - but it didn't work
my code is
string fileName = "hsl.dat";
string aktVerz = Directory.GetCurrentDirectory();
string pathString = aktVerz + @"\Misc";
string currentFile = pathString + @"\" + fileName;
StreamWriter Swriter = new StreamWriter(currentFile);
Error appears "Could not find a part of the path" but path exists ???
Try another variable:
string aktVerz = Path.GetDirectoryName( Assembly.GetEntryAssembly( ).Location );
my code is
string fileName = "hsl.dat";
string aktVerz = Directory.GetCurrentDirectory();
string pathString = aktVerz + @"\Misc";
string currentFile = pathString + @"\" + fileName;
StreamWriter Swriter = new StreamWriter(currentFile);
Are you sure that a subdirectory/folder named Misc already
exists on that path? If it doesn't then you will get that
error. If it does already exist your code should not error.
StreamWriter will create a new file, but it will NOT create
a new folder/directory from the path supplied.
yeah I'm sure :)
I doubt it. While there may be a subdir named Misc on
some path, the OS is saying one does NOT exist on the
path that IT sees as the current directory.
You may be making an incorrect assumption about what
IS the current directory when you run the program.
It often will be different when the program is run
in the IDE than when it is run from a command prompt
or from File Explorer. It will be different when you
run in the IDE from a Debug build than when you run
from a Release build.
You should be stepping through the program in the
debugger and examining each string to confirm that
they contain what you expect. Or display each string
on the console or in a MessageBox so you can confirm
the contents.