Created
February 10, 2009 01:09
-
-
Save Benrnz/61137 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Get a file and save as blob to a db | |
//Upload from file .png | |
string lFileName = @"C:\Inetpub\wwwroot\welcome.png"; | |
Image lOriginalImage = Image.FromFile(lFileName); | |
//ImageFormatConverter lConv = new ImageFormatConverter(); //Use to convert to different formats | |
MemoryStream lMs = new MemoryStream(); | |
lOriginalImage.Save(lMs, ImageFormat.Png); | |
Byte[] lBuffer = lMs.GetBuffer(); | |
lMs.Close(); | |
SqlConnection lConn = new SqlConnection(fConn); | |
string lSQL = "INSERT INTO Picture (Filename, Image)" + "VALUES (@Filename, @Image)"; | |
SqlCommand lCmd = new SqlCommand(lSQL, lConn); | |
lCmd.Parameters.Add(new SqlParameter("@Filename", SqlDbType.NVarChar, 50)).Value = lFileName; | |
lCmd.Parameters.Add(new SqlParameter("@Image", SqlDbType.Image)).Value = lBuffer; | |
lConn.Open(); | |
lCmd.ExecuteNonQuery(); | |
lConn.Close(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment