byte[] file = File.ReadAllBytes("C:\\Users\\gerasimenko-is\\Documents\\1940.pdf");
string file64 = Convert.ToBase64String(file);
string[] arr64String = StringSplitter.SplitByLength(file64, 300000).ToArray();
// Write the stream contents to a new file named "AllTxtFiles.txt".
for (int i = 0; i < arr64String.Length; i++) {
using (StreamWriter outfile = new StreamWriter(String.Format("C:\\Users\\gerasimenko-is\\Documents\\OutBase64_{0}.txt", i)))
{
outfile.Write(arr64String[i]);
}
}
String line = "";
try
{
using (StreamReader sr = new StreamReader("C:\\Users\\gerasimenko-is\\Documents\\InBase64.txt"))
{
line = sr.ReadToEnd();
}
}
catch (Exception ex)
{
Console.WriteLine("The file could not be read:");
Console.WriteLine(ex.Message);
}
byte[] byteArr = Convert.FromBase64String(line);
using (var imageFile = new FileStream("C:\\Users\\gerasimenko-is\\Documents\\Out.pdf", FileMode.Create))
{
imageFile.Write(byteArr, 0, byteArr.Length);
imageFile.Flush();
}
====================
public static class StringSplitter
{
public static IEnumerable<string> SplitByLength(this string str, int maxLength)
{
for (int index = 0; index < str.Length; index += maxLength)
{
yield return str.Substring(index, Math.Min(maxLength, str.Length - index));
}
}
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.