-1

How do I get the data of the file instead of the path? I used Directory.GetFile() and it returns the path of the file.
Now what I want is to convert the file(not the path) into base64. I know how to convert it to base64 but what I want to know is how do I get the data of the file.

Any idea? Sorry I'm new to c#

I dont know if data is the right terminology here :)

aznmik
  • 45
  • 1
  • 9
  • [This](https://stackoverflow.com/questions/7387085/how-to-read-an-entire-file-to-a-string-using-c) might be worth looking at. – devsmn May 27 '20 at 05:43
  • Does this answer your question? [Converting file into Base64String and back again](https://stackoverflow.com/questions/25919387/converting-file-into-base64string-and-back-again) – xdtTransform May 27 '20 at 06:06

1 Answers1

2

You can do it with a built-in Convert-funtion:

Byte[] bytes = File.ReadAllBytes("path");
String base64 = Convert.ToBase64String(bytes);
TWP
  • 250
  • 1
  • 5
  • 13