KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I've been saving a small XML data file to an external drive, no probs. But then I tried to use the ApplicationData folder and others, even C:\ but no luck. I'm getting an error like "Access to the path "C:\" denied". Just to confirm, the file is created and read fine with the current code, to an external drive. I guess this is something to do with security & permissions but I haven't found anything too useful. Thanks in advance if you can point me in the right direction on this one! string fipData = @"F:\IL2\SIIYM\SIIYM Data.xml"; // external drive ok :-) //string fipData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); //string fipData = @"C:\"; // if the XML data file doesn't exist, create it bool dataFileExists = File.Exists(fipData); if (dataFileExists) { // read the XML values XDocument xData = XDocument.Load(fipData); //... } else { // create & save the XML data file XElement xLastPath = new XElement(el_lastPath, ""); XElement xLastCode = new XElement(el_lastCode, ""); XElement xRoot = new XElement(el_root); xRoot.Add(xLastPath); xRoot.Add(xLastCode); XDocument newDataFile = new XDocument(); newDataFile.Add(xRoot); try { newDataFile.Save(fipData); } catch (Exception ex) { MessageBox.Show("Data file unable to be created. System message:{0}".Put(Environment.NewLine + Environment.NewLine + ex.Message)); } }
Tags (comma-separated)
Save Edits
Cancel