public static bool WriteFile(gpxType data, Uri url) { try { using (StreamWriter writer = new StreamWriter(url.AbsolutePath, false)) { XmlSerializer serializer = new XmlSerializer(typeof(gpxType), "http://www.topografix.com/GPX/1/1"); serializer.Serialize(writer, data); writer.Flush(); return(true); } } catch (Exception e) { Console.WriteLine($"An Error has occurred accessing file {url.AbsolutePath}.{Environment.NewLine} Details:{Environment.NewLine} {e.StackTrace}."); } return(false); }