Austin Muts

Austin Muts

  • 1.4k
  • 333
  • 126.4k

Reading files from a folder and converting to Json in C#

May 6 2020 11:29 AM
I have the code below,after retrieving the file i want to convert it to json.
Any help is appreciated.
  1. public string DownloadDocument(string documentname, string documentlocation)  
  2. {  
  3. string obj = string.Empty;  
  4. DirectoryInfo d = new DirectoryInfo(documentlocation);  
  5. FileInfo[] Files = d.GetFiles();  
  6. foreach (FileInfo file in Files)  
  7. {  
  8. if (file.Name.Contains(documentname))  
  9. {  
  10. //want to convert file to json as below but not working  
  11. //obj = Newtonsoft.Json.JsonConvert.SerializeObject(file);  
  12. }  
  13. }  
  14. return obj;  
  15. }  

Answers (2)