Advertisement
Guest User

Untitled

a guest
Jan 27th, 2015
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using Xamarin.Forms;
  4.  
  5. namespace TreningsApplikasjon.iOS
  6. {
  7. public class FileAccess : IFileAccess
  8. {
  9. public FileAccess ()
  10. {
  11. }
  12.  
  13. public bool Exists (string filename)
  14. {
  15. var filePath = GetFilePath (filename);
  16.  
  17. if (File.Exists (filePath)) {
  18. FileInfo finf = new FileInfo (filePath);
  19. return finf.Length > 0;
  20. } else
  21. return false;
  22. }
  23.  
  24. public string FullPath (string filename)
  25. {
  26. var filePath = GetFilePath (filename);
  27. return filePath;
  28. }
  29.  
  30. /*static string GetFilePath (string filename)
  31. {
  32. string documentsPath = Environment.GetFolderPath (Environment.SpecialFolder.Personal); // Documents folder
  33. string libraryPath = Path.Combine (documentsPath, "..", "Library"); // Library folder
  34. var path = Path.Combine(libraryPath, filename);
  35. return path;
  36. }*/
  37.  
  38.  
  39. static string GetFilePath (string filename)
  40. {
  41. var documentsPath = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
  42. var filePath = Path.Combine (documentsPath, filename);
  43. return filePath;
  44. }
  45.  
  46. public void WriteStream (string filename, Stream streamIn)
  47. {
  48. var filePath = GetFilePath (filename);
  49. using (var fs = File.Create (filePath)) {
  50. streamIn.CopyTo (fs);
  51. }
  52. }
  53.  
  54. public ImageSource GetImage(string filename){
  55. Image img = new Image ();
  56. return img.Source = ImageSource.FromFile (FullPath (filename));
  57. }
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement