Sometimes you need to put a file into a stirng or so.
Or you’ll find situations where you need to convert a string towards a byte[] array
and then convert this one to a file.
this code will put a file which can be a picture , pdf whatever into a byte[], then save this byte[] as a string.
If you should send this ‘string’ to somebody else and he ‘decompilles’ it back, he would eventually get your file.
using (FileStream _fileStream = new FileStream(_picturePath, FileMode.Open, FileAccess.Read))
{
byte[] _arr = new byte[_fileStream.Length];
_fileStream.Read(_arr, 0, Convert.ToInt32(_fileStream.Length));
_arrGlobal = _arr;
txtOuput.Text = Convert.ToBase64String(_arrGlobal, 0, _arrGlobal.Length);
}
The other way arround
string _outputPath = "your path here";
byte[] _arrTemp = Convert.FromBase64String(txtOuput.Text);
using (FileStream _fileStream = new FileStream(_outputPath, FileMode.Create))
{
_fileStream.Write(_arrTemp, 0, _arrTemp.Length);
}
These is a basic technique, but on the net there are many ways of doing it.
This one worked for me.
Hope it helps !