Create a field in your table named "AssetImage" with the type Image.
and field name scanId as type integer, this will be the unique id in the table to refer to that image as well.
STEP 2. How to SAVE the image
You must also have default.aspx file in your project if not then add one.
add 3 controls in your aspx file in design view.
1. FileUploader named FileUpload2
2. Image named ImgScanID
3. textbox named txtScanId to enter the id to retrieve the image
go to code behind aspx called default.cs
and paste the code below, this code will upload the file in database from fileuploader
using System; using System.Data; using System.Data.SqlClient; using System.Configuration; using System.Web.UI.WebControls;
using System.ComponentModel;using System.IO;
Description:
An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0116: A namespace does not directly contain members such as fields or methods
Source Error:
Line 8:
Line 9:
Line 10: byte[] myimage = new byte[FileUpload2.PostedFile.ContentLength];
Line 11: HttpPostedFile Image = FileUpload2.PostedFile;
Line 12: Image.InputStream.Read(myimage, 0, (int)FileUpload2.PostedFile.ContentLength);
Source File: c:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx.cs Line: 10
C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE> "C:\Windows\Microsoft.NET\Framework\v3.5\csc.exe" /t:library /utf8output /R:"C:\Windows\assembly\GAC_32\System.Web\2.0.0.0__b03f5f7f11d50a3a\System.Web.dll" /R:"C:\Windows\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll" /R:"C:\Windows\assembly\GAC_MSIL\System.Data.DataSetExtensions\3.5.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll" /R:"C:\Windows\assembly\GAC_32\System.EnterpriseServices\2.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll" /R:"C:\Windows\assembly\GAC_MSIL\System.IdentityModel\3.0.0.0__b77a5c561934e089\System.IdentityModel.dll" /R:"C:\Windows\assembly\GAC_MSIL\System.Core\3.5.0.0__b77a5c561934e089\System.Core.dll" /R:"C:\Windows\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll" /R:"C:\Windows\assembly\GAC_MSIL\System.Web.Extensions\3.5.0.0__31bf3856ad364e35\System.Web.Extensions.dll" /R:"C:\Windows\assembly\GAC_MSIL\System.Web.Services\2.0.0.0__b03f5f7f11d50a3a\System.Web.Services.dll" /R:"C:\Windows\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll" /R:"C:\Windows\assembly\GAC_MSIL\System.ServiceModel\3.0.0.0__b77a5c561934e089\System.ServiceModel.dll" /R:"C:\Windows\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll" /R:"C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll" /R:"C:\Windows\assembly\GAC_MSIL\System.ServiceModel.Web\3.5.0.0__31bf3856ad364e35\System.ServiceModel.Web.dll" /R:"C:\Windows\assembly\GAC_MSIL\System.WorkflowServices\3.5.0.0__31bf3856ad364e35\System.WorkflowServices.dll" /R:"C:\Windows\assembly\GAC_MSIL\System.Web.Mobile\2.0.0.0__b03f5f7f11d50a3a\System.Web.Mobile.dll" /R:"C:\Windows\assembly\GAC_MSIL\System.Xml.Linq\3.5.0.0__b77a5c561934e089\System.Xml.Linq.dll" /R:"C:\Windows\assembly\GAC_32\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll" /R:"C:\Windows\assembly\GAC_MSIL\System.Runtime.Serialization\3.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll" /out:"C:\Users\Lito\AppData\Local\Temp\Temporary ASP.NET Files\website2\fe0d863f\a5795b8d\App_Web_n-hi7st6.dll" /D:DEBUG /debug+ /optimize- /w:4 /nowarn:1659;1699;1701 /warnaserror- "C:\Users\Lito\AppData\Local\Temp\Temporary ASP.NET Files\website2\fe0d863f\a5795b8d\App_Web_n-hi7st6.0.cs" "C:\Users\Lito\AppData\Local\Temp\Temporary ASP.NET Files\website2\fe0d863f\a5795b8d\App_Web_n-hi7st6.1.cs" "C:\Users\Lito\AppData\Local\Temp\Temporary ASP.NET Files\website2\fe0d863f\a5795b8d\App_Web_n-hi7st6.2.cs" "C:\Users\Lito\AppData\Local\Temp\Temporary ASP.NET Files\website2\fe0d863f\a5795b8d\App_Web_n-hi7st6.3.cs"
Microsoft (R) Visual C# 2008 Compiler version 3.5.30729.4926
for Microsoft (R) .NET Framework version 3.5
Copyright (C) Microsoft Corporation. All rights reserved.
c:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Handler.ashx(24,11): error CS1519: Invalid token '(' in class, struct, or interface member declaration
c:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Handler.ashx(26,8): error CS1518: Expected class, delegate, enum, interface, or struct
c:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Handler.ashx(31,1): error CS1022: Type or namespace definition, or end-of-file expected
c:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx.cs(10,4): error CS0116: A namespace does not directly contain members such as fields or methods
c:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx.cs(10,9): error CS1001: Identifier expected
c:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx.cs(10,11): error CS1518: Expected class, delegate, enum, interface, or struct
c:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx.cs(10,25): error CS1518: Expected class, delegate, enum, interface, or struct
c:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx.cs(10,67): error CS1518: Expected class, delegate, enum, interface, or struct
c:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx.cs(14,68): error CS1001: Identifier expected
c:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx.cs(15,37): error CS1518: Expected class, delegate, enum, interface, or struct
c:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx.cs(25,38): error CS1518: Expected class, delegate, enum, interface, or struct
Line 1: #pragma checksum "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx" "{406ea660-64cf-4c82-b6f0-42d48172a799}" "FDE9C5FA50DDC2A82A6EB3009E0E65CE"
Line 2: //------------------------------------------------------------------------------
Line 3: // <auto-generated>
Line 4: // This code was generated by a tool.
Line 5: // Runtime Version:2.0.50727.4927
Line 6: //
Line 7: // Changes to this file may cause incorrect behavior and will be lost if
Line 8: // the code is regenerated.
Line 9: // </auto-generated>
Line 10: //------------------------------------------------------------------------------
Line 11:
Line 12:
Line 13:
Line 14: public partial class _Default : System.Web.SessionState.IRequiresSessionState {
Line 15:
Line 16:
Line 17: #line 13 "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx"
Line 18: protected global::System.Web.UI.WebControls.FileUpload FileUpload2;
Line 19:
Line 20: #line default
Line 21: #line hidden
Line 22:
Line 23:
Line 24: #line 18 "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx"
Line 25: protected global::System.Web.UI.WebControls.Image ImageScanId;
Line 26:
Line 27: #line default
Line 28: #line hidden
Line 29:
Line 30:
Line 31: #line 21 "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx"
Line 32: protected global::System.Web.UI.WebControls.TextBox TxtScanId;
Line 33:
Line 34: #line default
Line 35: #line hidden
Line 36:
Line 37:
Line 38: #line 10 "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx"
Line 39: protected global::System.Web.UI.HtmlControls.HtmlForm form1;
Line 40:
Line 41: #line default
Line 42: #line hidden
Line 43:
Line 44: protected System.Web.Profile.DefaultProfile Profile {
Line 45: get {
Line 46: return ((System.Web.Profile.DefaultProfile)(this.Context.Profile));
Line 47: }
Line 48: }
Line 49:
Line 50: protected System.Web.HttpApplication ApplicationInstance {
Line 51: get {
Line 52: return ((System.Web.HttpApplication)(this.Context.ApplicationInstance));
Line 53: }
Line 54: }
Line 55: }
Line 56: namespace ASP {
Line 57:
Line 58: #line 285 "C:\Windows\Microsoft.NET\Framework\v2.0.50727\Config\web.config"
Line 59: using System.Web.Profile;
Line 60:
Line 61: #line default
Line 62: #line hidden
Line 63:
Line 64: #line 280 "C:\Windows\Microsoft.NET\Framework\v2.0.50727\Config\web.config"
Line 65: using System.Text.RegularExpressions;
Line 66:
Line 67: #line default
Line 68: #line hidden
Line 69:
Line 70: #line 282 "C:\Windows\Microsoft.NET\Framework\v2.0.50727\Config\web.config"
Line 71: using System.Web.Caching;
Line 72:
Line 73: #line default
Line 74: #line hidden
Line 75:
Line 76: #line 278 "C:\Windows\Microsoft.NET\Framework\v2.0.50727\Config\web.config"
Line 77: using System.Configuration;
Line 78:
Line 79: #line default
Line 80: #line hidden
Line 81:
Line 82: #line 277 "C:\Windows\Microsoft.NET\Framework\v2.0.50727\Config\web.config"
Line 83: using System.Collections.Specialized;
Line 84:
Line 85: #line default
Line 86: #line hidden
Line 87:
Line 88: #line 13 "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx"
Line 89: using System.Web.UI.WebControls.WebParts;
Line 90:
Line 91: #line default
Line 92: #line hidden
Line 93:
Line 94: #line 289 "C:\Windows\Microsoft.NET\Framework\v2.0.50727\Config\web.config"
Line 95: using System.Web.UI.HtmlControls;
Line 96:
Line 97: #line default
Line 98: #line hidden
Line 99:
Line 100: #line 13 "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx"
Line 101: using System.Web.UI.WebControls;
Line 102:
Line 103: #line default
Line 104: #line hidden
Line 105:
Line 106: #line 13 "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx"
Line 107: using System.Web.UI;
Line 108:
Line 109: #line default
Line 110: #line hidden
Line 111:
Line 112: #line 276 "C:\Windows\Microsoft.NET\Framework\v2.0.50727\Config\web.config"
Line 113: using System.Collections;
Line 114:
Line 115: #line default
Line 116: #line hidden
Line 117:
Line 118: #line 275 "C:\Windows\Microsoft.NET\Framework\v2.0.50727\Config\web.config"
Line 119: using System;
Line 120:
Line 121: #line default
Line 122: #line hidden
Line 123:
Line 124: #line 284 "C:\Windows\Microsoft.NET\Framework\v2.0.50727\Config\web.config"
Line 125: using System.Web.Security;
Line 126:
Line 127: #line default
Line 128: #line hidden
Line 129:
Line 130: #line 281 "C:\Windows\Microsoft.NET\Framework\v2.0.50727\Config\web.config"
Line 131: using System.Web;
Line 132:
Line 133: #line default
Line 134: #line hidden
Line 135:
Line 136: #line 283 "C:\Windows\Microsoft.NET\Framework\v2.0.50727\Config\web.config"
Line 137: using System.Web.SessionState;
Line 138:
Line 139: #line default
Line 140: #line hidden
Line 141:
Line 142: #line 279 "C:\Windows\Microsoft.NET\Framework\v2.0.50727\Config\web.config"
Line 143: using System.Text;
Line 144:
Line 145: #line default
Line 146: #line hidden
Line 147:
Line 148:
Line 149: [System.Runtime.CompilerServices.CompilerGlobalScopeAttribute()]
Line 150: public class default_aspx : global::_Default, System.Web.IHttpHandler {
Line 151:
Line 152: private static bool @__initialized;
Line 153:
Line 154: private static object @__fileDependencies;
Line 155:
Line 156: [System.Diagnostics.DebuggerNonUserCodeAttribute()]
Line 157: public default_aspx() {
Line 158: string[] dependencies;
Line 159:
Line 160: #line 912304 "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx.cs"
Line 161: ((global::System.Web.UI.Page)(this)).AppRelativeVirtualPath = "~/Default.aspx";
Line 162:
Line 163: #line default
Line 164: #line hidden
Line 165: if ((global::ASP.default_aspx.@__initialized == false)) {
Line 166: dependencies = new string[2];
Line 167: dependencies[0] = "~/Default.aspx";
Line 168: dependencies[1] = "~/Default.aspx.cs";
Line 169: global::ASP.default_aspx.@__fileDependencies = this.GetWrappedFileDependencies(dependencies);
Line 170: global::ASP.default_aspx.@__initialized = true;
Line 171: }
Line 172: this.Server.ScriptTimeout = 30000000;
Line 173: }
Line 174:
Line 175: [System.Diagnostics.DebuggerNonUserCodeAttribute()]
Line 176: private global::System.Web.UI.HtmlControls.HtmlTitle @__BuildControl__control3() {
Line 177: global::System.Web.UI.HtmlControls.HtmlTitle @__ctrl;
Line 178:
Line 179: #line 7 "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx"
Line 180: @__ctrl = new global::System.Web.UI.HtmlControls.HtmlTitle();
Line 181:
Line 182: #line default
Line 183: #line hidden
Line 184: return @__ctrl;
Line 185: }
Line 186:
Line 187: [System.Diagnostics.DebuggerNonUserCodeAttribute()]
Line 188: private global::System.Web.UI.HtmlControls.HtmlHead @__BuildControl__control2() {
Line 189: global::System.Web.UI.HtmlControls.HtmlHead @__ctrl;
Line 190:
Line 191: #line 6 "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx"
Line 192: @__ctrl = new global::System.Web.UI.HtmlControls.HtmlHead("head");
Line 193:
Line 194: #line default
Line 195: #line hidden
Line 196: global::System.Web.UI.HtmlControls.HtmlTitle @__ctrl1;
Line 197:
Line 198: #line 6 "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx"
Line 199: @__ctrl1 = this.@__BuildControl__control3();
Line 200:
Line 201: #line default
Line 202: #line hidden
Line 203: System.Web.UI.IParserAccessor @__parser = ((System.Web.UI.IParserAccessor)(@__ctrl));
Line 204:
Line 205: #line 6 "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx"
Line 206: @__parser.AddParsedSubObject(@__ctrl1);
Line 207:
Line 208: #line default
Line 209: #line hidden
Line 210: return @__ctrl;
Line 211: }
Line 212:
Line 213: [System.Diagnostics.DebuggerNonUserCodeAttribute()]
Line 214: private global::System.Web.UI.WebControls.FileUpload @__BuildControlFileUpload2() {
Line 215: global::System.Web.UI.WebControls.FileUpload @__ctrl;
Line 216:
Line 217: #line 13 "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx"
Line 218: @__ctrl = new global::System.Web.UI.WebControls.FileUpload();
Line 219:
Line 220: #line default
Line 221: #line hidden
Line 222: this.FileUpload2 = @__ctrl;
Line 223: @__ctrl.ApplyStyleSheetSkin(this);
Line 224:
Line 225: #line 13 "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx"
Line 226: @__ctrl.ID = "FileUpload2";
Line 227:
Line 228: #line default
Line 229: #line hidden
Line 230: return @__ctrl;
Line 231: }
Line 232:
Line 233: [System.Diagnostics.DebuggerNonUserCodeAttribute()]
Line 234: private global::System.Web.UI.WebControls.Image @__BuildControlImageScanId() {
Line 235: global::System.Web.UI.WebControls.Image @__ctrl;
Line 236:
Line 237: #line 18 "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx"
Line 238: @__ctrl = new global::System.Web.UI.WebControls.Image();
Line 239:
Line 240: #line default
Line 241: #line hidden
Line 242: this.ImageScanId = @__ctrl;
Line 243: @__ctrl.ApplyStyleSheetSkin(this);
Line 244:
Line 245: #line 18 "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx"
Line 246: @__ctrl.ID = "ImageScanId";
Line 247:
Line 248: #line default
Line 249: #line hidden
Line 250: return @__ctrl;
Line 251: }
Line 252:
Line 253: [System.Diagnostics.DebuggerNonUserCodeAttribute()]
Line 254: private global::System.Web.UI.WebControls.TextBox @__BuildControlTxtScanId() {
Line 255: global::System.Web.UI.WebControls.TextBox @__ctrl;
Line 256:
Line 257: #line 21 "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx"
Line 258: @__ctrl = new global::System.Web.UI.WebControls.TextBox();
Line 259:
Line 260: #line default
Line 261: #line hidden
Line 262: this.TxtScanId = @__ctrl;
Line 263: @__ctrl.ApplyStyleSheetSkin(this);
Line 264:
Line 265: #line 21 "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx"
Line 266: @__ctrl.ID = "TxtScanId";
Line 267:
Line 268: #line default
Line 269: #line hidden
Line 270: return @__ctrl;
Line 271: }
Line 272:
Line 273: [System.Diagnostics.DebuggerNonUserCodeAttribute()]
Line 274: private global::System.Web.UI.HtmlControls.HtmlForm @__BuildControlform1() {
Line 275: global::System.Web.UI.HtmlControls.HtmlForm @__ctrl;
Line 276:
Line 277: #line 10 "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx"
Line 278: @__ctrl = new global::System.Web.UI.HtmlControls.HtmlForm();
Line 279:
Line 280: #line default
Line 281: #line hidden
Line 282: this.form1 = @__ctrl;
Line 283:
Line 284: #line 10 "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx"
Line 285: @__ctrl.ID = "form1";
Line 286:
Line 287: #line default
Line 288: #line hidden
Line 289: System.Web.UI.IParserAccessor @__parser = ((System.Web.UI.IParserAccessor)(@__ctrl));
Line 290:
Line 291: #line 10 "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx"
Line 292: @__parser.AddParsedSubObject(new System.Web.UI.LiteralControl("\r\n <div>\r\n \r\n "));
Line 293:
Line 294: #line default
Line 295: #line hidden
Line 296: global::System.Web.UI.WebControls.FileUpload @__ctrl1;
Line 297:
Line 298: #line 10 "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx"
Line 299: @__ctrl1 = this.@__BuildControlFileUpload2();
Line 300:
Line 301: #line default
Line 302: #line hidden
Line 303:
Line 304: #line 10 "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx"
Line 305: @__parser.AddParsedSubObject(@__ctrl1);
Line 306:
Line 307: #line default
Line 308: #line hidden
Line 309:
Line 310: #line 10 "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx"
Line 311: @__parser.AddParsedSubObject(new System.Web.UI.LiteralControl("\r\n <br />\r\n <br />\r\n \r\n </div>\r\n "));
Line 312:
Line 313: #line default
Line 314: #line hidden
Line 315: global::System.Web.UI.WebControls.Image @__ctrl2;
Line 316:
Line 317: #line 10 "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx"
Line 318: @__ctrl2 = this.@__BuildControlImageScanId();
Line 319:
Line 320: #line default
Line 321: #line hidden
Line 322:
Line 323: #line 10 "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx"
Line 324: @__parser.AddParsedSubObject(@__ctrl2);
Line 325:
Line 326: #line default
Line 327: #line hidden
Line 328:
Line 329: #line 10 "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx"
Line 330: @__parser.AddParsedSubObject(new System.Web.UI.LiteralControl("\r\n <br />\r\n <br />\r\n "));
Line 331:
Line 332: #line default
Line 333: #line hidden
Line 334: global::System.Web.UI.WebControls.TextBox @__ctrl3;
Line 335:
Line 336: #line 10 "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx"
Line 337: @__ctrl3 = this.@__BuildControlTxtScanId();
Line 338:
Line 339: #line default
Line 340: #line hidden
Line 341:
Line 342: #line 10 "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx"
Line 343: @__parser.AddParsedSubObject(@__ctrl3);
Line 344:
Line 345: #line default
Line 346: #line hidden
Line 347:
Line 348: #line 10 "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx"
Line 349: @__parser.AddParsedSubObject(new System.Web.UI.LiteralControl("\r\n "));
Line 350:
Line 351: #line default
Line 352: #line hidden
Line 353: return @__ctrl;
Line 354: }
Line 355:
Line 356: [System.Diagnostics.DebuggerNonUserCodeAttribute()]
Line 357: private void @__BuildControlTree(default_aspx @__ctrl) {
Line 358:
Line 359: #line 1 "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx"
Line 360: this.InitializeCulture();
Line 361:
Line 362: #line default
Line 363: #line hidden
Line 364: System.Web.UI.IParserAccessor @__parser = ((System.Web.UI.IParserAccessor)(@__ctrl));
Line 365:
Line 366: #line 1 "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx"
Line 367: @__parser.AddParsedSubObject(new System.Web.UI.LiteralControl("\r\n\r\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3" +
Line 368: ".org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\r\n\r\n<html xmlns=\"http://www.w3.org/1" +
Line 369: "999/xhtml\">\r\n"));
Line 370:
Line 371: #line default
Line 372: #line hidden
Line 373: global::System.Web.UI.HtmlControls.HtmlHead @__ctrl1;
Line 374:
Line 375: #line 1 "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx"
Line 376: @__ctrl1 = this.@__BuildControl__control2();
Line 377:
Line 378: #line default
Line 379: #line hidden
Line 380:
Line 381: #line 1 "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx"
Line 382: @__parser.AddParsedSubObject(@__ctrl1);
Line 383:
Line 384: #line default
Line 385: #line hidden
Line 386:
Line 387: #line 1 "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx"
Line 388: @__parser.AddParsedSubObject(new System.Web.UI.LiteralControl("\r\n<body>\r\n "));
Line 389:
Line 390: #line default
Line 391: #line hidden
Line 392: global::System.Web.UI.HtmlControls.HtmlForm @__ctrl2;
Line 393:
Line 394: #line 1 "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx"
Line 395: @__ctrl2 = this.@__BuildControlform1();
Line 396:
Line 397: #line default
Line 398: #line hidden
Line 399:
Line 400: #line 1 "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx"
Line 401: @__parser.AddParsedSubObject(@__ctrl2);
Line 402:
Line 403: #line default
Line 404: #line hidden
Line 405:
Line 406: #line 1 "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx"
Line 407: @__parser.AddParsedSubObject(new System.Web.UI.LiteralControl("\r\n</body>\r\n</html>\r\n"));
Line 408:
Line 409: #line default
Line 410: #line hidden
Line 411: }
Line 412:
Line 413:
Line 414: #line 912304 "C:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx.cs"
Line 415: [System.Diagnostics.DebuggerNonUserCodeAttribute()]
Line 416: protected override void FrameworkInitialize() {
Line 417: base.FrameworkInitialize();
Line 418: this.@__BuildControlTree(this);
Line 419: this.AddWrappedFileDependencies(global::ASP.default_aspx.@__fileDependencies);
Line 420: this.Request.ValidateInput();
Line 421: }
Line 422:
Line 423: #line default
Line 424: #line hidden
Line 425:
Line 426: [System.Diagnostics.DebuggerNonUserCodeAttribute()]
Line 427: public override int GetTypeHashCode() {
Line 428: return -295576756;
Line 429: }
Line 430:
Line 431: [System.Diagnostics.DebuggerNonUserCodeAttribute()]
Line 432: public override void ProcessRequest(System.Web.HttpContext context) {
Line 433: base.ProcessRequest(context);
Line 434: }
Line 435: }
Line 436: }
Line 437:
</div>
Version Information: Microsoft .NET Framework Version:2.0.50727.4927; ASP.NET Version:2.0.50727.4927
How are you retriveing image to display in web page ?
I think,first you hv to write a method to create image file.and here you pass the filecontent of database in bytes.I think it will automatically create the image file in specified drive.
First tell me are you able to display image in browser from database. you need a webpage which has only control to display. when image is displayed in web page then right clik on image and copy the path of it.(Just test).
Now only few line(I tested,it work,if you are able to do first paragraph. write this code in same page,where you displaying image.
In the same senario how we can Insert/Update OLE Attachment(Binary datatype) from one source table to other destination table by usint SQL Server 2000 not with C# fronend code.
mainiabhay
Member
4 Points
4 Posts
save retrieve image in SQL SERVER database c sharp
Jun 23, 2009 01:47 AM|LINK
Hi All,
My this post is for people who are relatively new to ASP.NET/c-sharp programming and are learning new tricks.
This trick tells about how to save / retrieve image in database table. i must credit the link below which was of lot of help.
http://www.aspdotnetcodes.com/Insert_Images_Database.aspx
PLEASE FOLLOW STEPS BELOW:
STEP 1. prepare database
Create a field in your table named "AssetImage" with the type Image.
and field name scanId as type integer, this will be the unique id in the table to refer to that image as well.
STEP 2. How to SAVE the image
You must also have default.aspx file in your project if not then add one.
add 3 controls in your aspx file in design view.
1. FileUploader named FileUpload2
2. Image named ImgScanID
3. textbox named txtScanId to enter the id to retrieve the image
go to code behind aspx called default.cs
and paste the code below, this code will upload the file in database from fileuploader
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.UI.WebControls;
using System.ComponentModel;using System.IO;
byte[] myimage = new byte[FileUpload2.PostedFile.ContentLength];
HttpPostedFile Image = FileUpload2.PostedFile;
Image.InputStream.Read(myimage, 0, (int)FileUpload2.PostedFile.ContentLength);
string strConnection = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
SqlConnection conn = new SqlConnection(strConnection);
//below code will update the existing entries in table, you can use insert statement instead to add new data.
//i assumed that you have existing data and are saving pictures
string strSQLW = "UPDATE [Tbl_Name] " +
"SET [assetimage] = @image " +
"Where Scanid='" + LblScanID.Text + "'";
SqlCommand cmdSQLWU = new SqlCommand(strSQLW);
cmdSQLWU.Parameters.Add("@image", SqlDbType.Image, myimage.Length).Value = myimage;
cmdSQLWU.Connection = conn;
cmdSQLWU.Connection.Open();
cmdSQLWU.ExecuteNonQuery();
pavalos
Member
1 Points
1 Post
Re: save retrieve image in SQL SERVER database c sharp
Mar 26, 2010 12:09 AM|LINK
I got this error
Server Error in '/WebSite2' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.Compiler Error Message: CS0116: A namespace does not directly contain members such as fields or methods
Source Error:
Source File: c:\Users\Lito\Documents\Visual Studio 2008\WebSites\WebSite2\Default.aspx.cs Line: 10
<div onclick="OnToggleTOCLevel1('compilerOutputDiv')">Show Detailed Compiler Output:</div> <div style="DISPLAY: none" id=compilerOutputDiv sizcache="0" sizset="1" mce_style="DISPLAY: none">
<div onclick="OnToggleTOCLevel1('dynamicCodeDiv')">Show Complete Compilation Source:</div> <div style="DISPLAY: none" id=dynamicCodeDiv sizcache="0" sizset="2" mce_style="DISPLAY: none">
Version Information: Microsoft .NET Framework Version:2.0.50727.4927; ASP.NET Version:2.0.50727.4927
error handler
KumarHarsh
All-Star
15133 Points
3647 Posts
Re: save retrieve image in SQL SERVER database c sharp
Apr 24, 2010 06:32 AM|LINK
Hi,
Many many thanks.
It helped me.
Kumar Harsh
DivakarGanta
Member
39 Points
140 Posts
Re: save retrieve image in SQL SERVER database c sharp
Aug 13, 2010 11:23 AM|LINK
I want .NET code to save all images in Local folder from Data base Table.
for Example: I have table tbl_Images with 1000 Images.
So, I want .NET code to save 1000 Images to a local Folder on 1000 image files.
Thanks,
Divakar.
KumarHarsh
All-Star
15133 Points
3647 Posts
Re: save retrieve image in SQL SERVER database c sharp
Aug 13, 2010 11:55 AM|LINK
How are you retriveing image to display in web page ?
I think,first you hv to write a method to create image file.and here you pass the filecontent of database in bytes.I think it will automatically create the image file in specified drive.
Kumar Harsh
DivakarGanta
Member
39 Points
140 Posts
Re: save retrieve image in SQL SERVER database c sharp
Aug 13, 2010 12:31 PM|LINK
Yes, for this process I need Code in .NET?
KumarHarsh
All-Star
15133 Points
3647 Posts
Re: save retrieve image in SQL SERVER database c sharp
Aug 13, 2010 12:47 PM|LINK
I do my best to write code for it.
But you can google it "Convert binary to image" in c#.
Kumar Harsh
KumarHarsh
All-Star
15133 Points
3647 Posts
Re: save retrieve image in SQL SERVER database c sharp
Aug 14, 2010 11:40 AM|LINK
First tell me are you able to display image in browser from database. you need a webpage which has only control to display. when image is displayed in web page then right clik on image and copy the path of it.(Just test).
Now only few line(I tested,it work,if you are able to do first paragraph. write this code in same page,where you displaying image.
string strfilefullpath=http://localhost:2331/WebForm3.aspx;
string strNewfilenametoSave="~/image2.gif";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strfilefullpath);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
System.Drawing.Image img1 = System.Drawing.Image.FromStream(response.GetResponseStream()); img1.Save(Server.MapPath(strNewfilenametoSave));
Kumar Harsh
hans_v
All-Star
35986 Points
6550 Posts
Re: save retrieve image in SQL SERVER database c sharp
Aug 14, 2010 11:53 AM|LINK
Divakar, Next time, please don't reopen old threads but start a new thread yourself to avoid thread jacking...
http://www.mikesdotnetting.com/Article/69
DivakarGanta
Member
39 Points
140 Posts
Re: save retrieve image in SQL SERVER database c sharp
Aug 30, 2010 12:00 PM|LINK
Hi All,
In the same senario how we can Insert/Update OLE Attachment(Binary datatype) from one source table to other destination table by usint SQL Server 2000 not with C# fronend code.
Appreciated if you can give fix on this
regads,
Divakar.