.net - Upload images to SQL Server 2005 using ASP.Net MVC? -


I know that there is a way to upload pictures to the database in the form of image type or alpha type, however, In the week, I can not find anything that can help me, so this is really my last resort, if anyone knows how to upload images to a database, I am using SQL Server 2005 Express I am

Thanks

You can access the file archive of the request and upload each uploaded file Should be able to get an HttpPostedFile example. Hold the inputstream from the file and read it in the byte array for the column property. I am assuming that how your DAL maps to Verbunary for your business class - if not, it is an original image, then you have to make a conversion before saving. The example below uses LINQ2SQL.

  MyClass obj = new MyClass (); Obj.Name = Request ["name"]; // Other properties obj.Alt = Request ["altteext"]; HttpPostedFile file = Request. Files [0]; If (file! = Null) {obj.Image image = new byte [file.ContentLength]; Use the file.Read (obj.Image, 0, file.ContentLength)}} (Data Contestect Reference = New DataContact ()) {context.InsertOnSubmit (obj); context.SubmitChanges ();}  

Comments