Doesnt have the permision to save the file

So I have been working on a Window Application and start working on a way to save the settings in a file. When I tried creating and saving this file by using
doc.Save("C:\\Program Files (x86)\\Hoi4ModdingTool");
doc.Save("C:\\Program Files (x86)\\Hoi4ModdingTool");
I get the error that it doesnt have the right permissions for that. What should I do to fix that?
17 Replies
x0rld
x0rld9mo ago
use your program in admin
TheOneAndOnly
TheOneAndOnly9mo ago
I runned VS in admin but that doesnt fix it
GaSkia
GaSkia9mo ago
can you post the code
TheOneAndOnly
TheOneAndOnly9mo ago
The exact function I trying to run is as following:
C++
public void SaveSettings()
{
var doc = new XDocument();
using (var writer = doc.CreateWriter())
{
var serializer = new XmlSerializer(typeof(SettingsData));

serializer.Serialize(writer, this);
}

doc.Save("C:\\Program Files (x86)\\Hoi4ModdingTool");
}
C++
public void SaveSettings()
{
var doc = new XDocument();
using (var writer = doc.CreateWriter())
{
var serializer = new XmlSerializer(typeof(SettingsData));

serializer.Serialize(writer, this);
}

doc.Save("C:\\Program Files (x86)\\Hoi4ModdingTool");
}
x0rld
x0rld9mo ago
Hoi4ModdingTool is supposed to be a file ?
GaSkia
GaSkia9mo ago
What does the error says
TheOneAndOnly
TheOneAndOnly9mo ago
I my lord Im a idiot I cant get the colors to work once more Anyhow
x0rld
x0rld9mo ago
it's cs not c#
TheOneAndOnly
TheOneAndOnly9mo ago
The folder
GaSkia
GaSkia9mo ago
because the things are 2 u missed the @
TheOneAndOnly
TheOneAndOnly9mo ago
Ssstt I dont know what your talking about 😅
GaSkia
GaSkia9mo ago
and the other I forgot beucase I'm dumb
x0rld
x0rld9mo ago
your supposed to give the file name
GaSkia
GaSkia9mo ago
console.writeline("\\"); // writes \
console.writeline(@"\\"); // writes \\
console.writeline("\\"); // writes \
console.writeline(@"\\"); // writes \\
TheOneAndOnly
TheOneAndOnly9mo ago
So I compleetly miss understood the function? Cool, but than how do you save it in a specific folder?
x0rld
x0rld9mo ago
doc.Save("C:\\Program Files (x86)\\Hoi4ModdingTool\\Foo.xml");
TheOneAndOnly
TheOneAndOnly9mo ago
Ah in that way ofcourse that makes sense let me test it out Thankss