C
C#•14mo ago
TheOneAndOnly

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 👻 🎃
use your program in admin
TheOneAndOnly
TheOneAndOnlyOP•14mo ago
I runned VS in admin but that doesnt fix it
GaSkia
GaSkia•14mo ago
can you post the code
TheOneAndOnly
TheOneAndOnlyOP•14mo 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 👻 🎃
Hoi4ModdingTool is supposed to be a file ?
GaSkia
GaSkia•14mo ago
What does the error says
TheOneAndOnly
TheOneAndOnlyOP•14mo ago
I my lord Im a idiot I cant get the colors to work once more Anyhow
x0rld 👻 🎃
it's cs not c#
TheOneAndOnly
TheOneAndOnlyOP•14mo ago
The folder
GaSkia
GaSkia•14mo ago
because the things are 2 u missed the @
TheOneAndOnly
TheOneAndOnlyOP•14mo ago
Ssstt I dont know what your talking about 😅
GaSkia
GaSkia•14mo ago
and the other I forgot beucase I'm dumb
x0rld 👻 🎃
your supposed to give the file name
GaSkia
GaSkia•14mo ago
console.writeline("\\"); // writes \
console.writeline(@"\\"); // writes \\
console.writeline("\\"); // writes \
console.writeline(@"\\"); // writes \\
TheOneAndOnly
TheOneAndOnlyOP•14mo ago
So I compleetly miss understood the function? Cool, but than how do you save it in a specific folder?
x0rld 👻 🎃
doc.Save("C:\\Program Files (x86)\\Hoi4ModdingTool\\Foo.xml");
TheOneAndOnly
TheOneAndOnlyOP•14mo ago
Ah in that way ofcourse that makes sense let me test it out Thankss
Want results from more Discord servers?
Add your server