File Handling (Android and IOS)

Hello,

I am currently working on a book management for Android and IOS. I would like to create a CSV file with the current stock and save it. My question is how do I find a path for Android and IOS where I can write and read?

Answers

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Xamarin Essentials includes file system helpers
    https://docs.microsoft.com/en-us/xamarin/essentials/

  • LTBLTB Member ✭✭
        private void FileGeneratorClicked(object sender, EventArgs e)
        {
    
            string date = DateTime.Now.ToString("dd.MM.yyyy HH.mm.ss");
            string name = "Lagerstand vom " + date + ".xls";
            var location = FileSystem.AppDataDirectory;
            string path = Path.Combine(location, name);
    
            List<List<string>> data = new List<List<string>>()
            {
                new List<string> { "AWL", "987-5-417-1", "6" },
                new List<string> { "DTSM", "362-0-258-9", "63"},
            };
    
            if (Directory.Exists(location))
            {
                Directory.CreateDirectory(location);
            }
    
            File.WriteAllText(name, createHTMLTable(data));
    
            Process.Start(path);
        }
    
    
    
        public static string createHTMLTable(List<List<string>> data)
        {
            StringBuilder sb = new StringBuilder("<table>\r\n");
            foreach (List<string> row in data)
            {
                sb.AppendLine("<tr>");
                foreach (string col in row)
                {
                    sb.AppendLine("<td>" + col + "</td\r\n>");
                }
                sb.AppendLine("</tr>\r\n");
            }
            sb.AppendLine("</table>");
    
            return sb.ToString();
        }
    
  • LTBLTB Member ✭✭

    It comes a Win32Exception

Sign In or Register to comment.