SunQuest
 
           Code Bank
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingCode Bank

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old February 13th, 2004, 01:06 PM
ricksterval's Avatar
ricksterval ricksterval is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 31 ricksterval User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Create webservice to retrieve image from database

[WebMethod]

...A sample code to create webservice to retrieve image from database

- The Webservice uses DataReader to read the data from the database table and returns byte array.
- The client retrieves the data in form of byte array and saves it in the file with specified format .
- The client code uses System.IO.MemoryStream , System.Drawing.Bitmap and System.Drawing.Imaging.ImageFormat namespace to save the image.

[bold]Step 1: WebService (WSIMGjpeg.asmx)[/bold]
[code]
[WebMethod]

public byte [] showImage(Int32 empid)

{

SqlConnection myconnection = new SqlConnection ("Server=localhost;uid=sa;password=;database=northwi nd;");

SqlCommand mycommand = new SqlCommand ("Select Employeeid, FirstName,Photo from Employees where employeeid =" + empid, myconnection);

myconnection.Open ();

SqlDataReader dr= mycommand.ExecuteReader();

dr.Read();



byte[] imgbyte =(byte[]) dr["Photo"];


return imgbyte;

}



[bold]Step 2: Client[/bold]

private void Page_Load(object sender, System.EventArgs e)

{

// Put user code to initialize the page here

localhost.WSIMGjpeg obj= new localhost.WSIMGjpeg();

byte[] data = obj.showImage (2);

Int32 offset =78;

System.IO.MemoryStream mstream = new System.IO.MemoryStream ();

mstream.Write(data, offset, data.Length - offset);


System.Drawing.Bitmap bmp= new System.Drawing.Bitmap(mstream);

bmp.Save(Server.MapPath ("empimg.jpeg"), System.Drawing.Imaging.ImageFormat.Jpeg );

mstream.Close();

// Drag and drop <asp:image> tag on webform

Image1.ImageUrl = Server.MapPath("empimg.jpeg");

}

Read Complete Articles

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingCode Bank > Create webservice to retrieve image from database


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway