{"id":2712,"date":"2018-05-17T16:36:45","date_gmt":"2018-05-17T14:36:45","guid":{"rendered":"http:\/\/www.capri-soft.de\/blog\/?p=2712"},"modified":"2018-06-07T08:30:47","modified_gmt":"2018-06-07T06:30:47","slug":"asp-net-sparx-systems-enterprise-architect-read-binary-image-from-database-blob-and-show-display-it-on-a-webpage","status":"publish","type":"post","link":"https:\/\/www.capri-soft.de\/blog\/?p=2712","title":{"rendered":"ASP.NET \/ Sparx Systems Enterprise Architect : Read binary Image from Database ( BLOB ) and show \/ display it on a webpage"},"content":{"rendered":"<h1>Problem<\/h1>\n<p>A binary picture that has been saved in a database or an Access File (i.e. of the Sparx Systems Enterprise Architect) shall be displayed on a web page.<\/p>\n<h1>Approach<\/h1>\n<ol>\n<li>Create a new ASP.NET Webform and name it GetImage.aspx<\/li>\n<li>Go to the Page_Load function in it<\/li>\n<li>Paste the code under solution in the area in customize according your data structure (here it is Sparx EA).<\/li>\n<li>Create a img-Tag in HTML, that has a src-Attribute pointing to that webpage with a get parameter img={your image id}<\/li>\n<li>Use Response.BinaryWrite in the way shown below<\/li>\n<\/ol>\n<h1>Solution<\/h1>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nusing System;\r\nusing System.Collections.Generic;\r\nusing System.Data.OleDb;\r\nusing System.Linq;\r\nusing System.Web;\r\nusing System.Web.UI;\r\nusing System.Web.UI.WebControls;\r\n\r\npublic partial class GetImage : System.Web.UI.Page\r\n{\r\n    \/\/ Mit folgender URL Kann ein Bild nun rausgeladen werden \r\n    \/\/ http:\/\/localhost:51241\/GetImage.aspx?img=343868582\r\n    \/\/ und entsprechend in HTML \u00fcber den Image-Tag geladen werden:\r\n    \/\/ &lt;img src=&quot;GetImage.aspx?img=343868582&quot; \/&gt;\r\n    protected void Page_Load(object sender, EventArgs e)\r\n    {\r\n        string sqlStatement = @&quot;\r\n            SELECT Image \r\n            FROM t_image \r\n            WHERE ImageID={ImageID}         \r\n        &quot;;\r\n\r\n        sqlStatement = sqlStatement.Replace(&quot;{ImageID}&quot;, Request.QueryString&#x5B;&quot;img&quot;].Trim());\r\n\r\n        OleDbConnection conn = new OleDbConnection(MyConfigurationManager.eapFilePath);\r\n\r\n        try\r\n        {\r\n            conn.Open();\r\n            OleDbCommand comm = new OleDbCommand();\r\n            comm.Connection = conn;\r\n            comm.CommandText = sqlStatement;\r\n\r\n            OleDbDataReader reader = comm.ExecuteReader();\r\n\r\n            while (reader.Read())\r\n            {\r\n                Response.ContentType = &quot;image\/jpeg&quot;; \/\/ if your image is a jpeg of course\r\n                Response.BinaryWrite((byte&#x5B;])reader.GetValue(0));\r\n            }\r\n        }\r\n        catch (Exception ex)\r\n        {\r\n            \/\/return e.Message;\r\n        }\r\n        finally\r\n        {\r\n            conn.Close();\r\n        }\r\n    }\r\n}\r\n<\/pre>\n<iframe src=\"http:\/\/www.facebook.com\/plugins\/like.php?href=https%3A%2F%2Fwww.capri-soft.de%2Fblog%2F%3Fp%3D2712&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light\" scrolling=\"no\" frameborder=\"0\" allowTransparency=\"true\" style=\"border:none; overflow:hidden; width:450px;margin-top:5px;\"><\/iframe>","protected":false},"excerpt":{"rendered":"<p>Problem A binary picture that has been saved in a database or an Access File (i.e. of the Sparx Systems Enterprise Architect) shall be displayed on a web page. Approach Create a new ASP.NET Webform and name it GetImage.aspx Go to the Page_Load function in it Paste the code under solution in the area in &hellip; <a href=\"https:\/\/www.capri-soft.de\/blog\/?p=2712\" class=\"more-link\"><span class=\"screen-reader-text\">ASP.NET \/ Sparx Systems Enterprise Architect : Read binary Image from Database ( BLOB ) and show \/ display it on a webpage<\/span> weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4,16,33,10,11,28,43],"tags":[],"class_list":["post-2712","post","type-post","status-publish","format-standard","hentry","category-net","category-access","category-c","category-datenbanken","category-ms-sql-server","category-sparx-systems-enterprise-architect","category-sql"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4yGeN-HK","jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2712","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2712"}],"version-history":[{"count":4,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2712\/revisions"}],"predecessor-version":[{"id":2716,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2712\/revisions\/2716"}],"wp:attachment":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2712"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2712"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2712"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}