Advertisement
Guest User

Untitled

a guest
Nov 21st, 2014
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. namespace RetGet.data
  2.  
  3. [DataMember]
  4.  
  5. public int Id { get; set; }
  6. [DataMember]
  7.  
  8. public string RetPath { get; set; }
  9.  
  10. }
  11. }
  12.  
  13. //Ref to the model
  14. RetFil retfil = new RetFil();
  15. //Network drive path (Might have to change/Access permissions)
  16. string dirPath = @"HERE IS THE NETWORK DRIVE PATH";
  17.  
  18. List<string> files;
  19. List<object> filesFormatted;
  20.  
  21.  
  22.  
  23. public void SetUpLists()
  24. {
  25.  
  26. //Collects all the .ret files in the dirPath and it's subfolders.
  27. files = new List<string>(Directory.GetFiles(dirPath, "*.ret", SearchOption.AllDirectories));
  28. filesFormatted = new List<object>();
  29.  
  30.  
  31. }
  32.  
  33. // GET: api/Ret/5
  34. [ResponseType(typeof(RetFil))]
  35. public IHttpActionResult GetRet(string id)
  36. {
  37.  
  38. SetUpLists();
  39.  
  40. //Adds each filename and format it (removing "" from the file path) to the list of objects
  41. foreach (var file in files)
  42. {
  43.  
  44. var pathToString = file.Substring(file.LastIndexOf("\"));
  45. if (pathToString.Contains(id))
  46. {
  47. filesFormatted.Add(new { pathToString });
  48. }
  49.  
  50. }
  51.  
  52. //Returns the list of object. Web Api will convert to JSON automatic.
  53.  
  54. return Ok(filesFormatted);
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement