Skip to content

Instantly share code, notes, and snippets.

@simoncowie
Last active March 11, 2024 10:07
Show Gist options
  • Save simoncowie/57669d20c591df4dba57c35722741d10 to your computer and use it in GitHub Desktop.
Save simoncowie/57669d20c591df4dba57c35722741d10 to your computer and use it in GitHub Desktop.
Example: Simple way to save and fetch binary data to/from files using linqpad
//Set Language to "C# Program" in linqPad
void Main()
{
var peopleWithPics = TblPersons
.Where(p => p.ProfilePicture != null)
.Select(p => new { p.PersonID, p.ProfilePicture });
foreach(var p in peopleWithPics)
{
System.IO.File.WriteAllBytes(
Path.Combine(@"D:\temp\", p.PersonID.ToString() + ".jpg"),
p.ProfilePicture.ToArray());
}
}
//Set Language to "C# Program" in linqPad
void Main()
{
var file = System.IO.File.ReadAllBytes(@"D:\temp\4980.jpg");
var person = TblPersons.First(p => p.PersonID == 5025);
person.ProfilePicture = file;
SubmitChanges();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment