Skip to content

Instantly share code, notes, and snippets.

@beisong7
Created June 5, 2020 10:58
Show Gist options
  • Save beisong7/93a05ff27d1351e6544094d4ed873005 to your computer and use it in GitHub Desktop.
Save beisong7/93a05ff27d1351e6544094d4ed873005 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class public_convert : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
njcDataClassesDataContext db = new njcDataClassesDataContext();
ImageConverter converter = new ImageConverter();
foreach (var lawyer in db.Lawyers)
{
if (lawyer.Photo != null)
{
//setting the filename
string filename = lawyer.Id.ToString() + lawyer.EnrollmentNumber.ToString();
//setting the lawyer image url with the file name
//lawyer.ImgUrl = converter.saveToFile(lawyer.Photo, filename).ToString();
var url = converter.saveToFile(lawyer.Photo, filename).ToString();
var Id = lawyer.Id;
//unset the binary data from lawyer info
//lawyer.Photo = null; //commented out to be sure it works first
//save to db
//njc Mynjc = new njc(db);
lawyer.ImgUrl = url;
//db.SubmitChanges();
db.ExecuteCommand("UPDATE Lawyers SET ImgUrl = '" + url + "' WHERE Id = " + Id);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment