473,799 Members | 3,009 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Saving and retriving images in database through WS

Hi there.

I'm developing a small application that uses Web Services to access database
and store data.

At some point, I store some images, by inserting the absolute image path
into a varchar field (SQL Server 2005). Images themselves are copied to that
path on the server. To read the images, I just use this path.

However, some workstations have to authenticate the server that path. To
avoid other problems, like deleting those images, I want to store images
directly in database, on a Image field.

So, after this long intro, I could have this code on server side (WS), to
save images:

/****/
[WebMethod]
public void SaveImage( string name, byte[] imageData )
{
//use the web.config to store the connection string
SqlConnection connection = new
SqlConnection(C onfigurationSet tings.AppSettin gs["DSN"]);
SqlCommand command = new SqlCommand( "INSERT INTO Image(name, data)
VALUES (@name, @data)", connection );
SqlParameter pName = new SqlParameter( "@name", SqlDbType.VarCh ar,50 );
pName.Value = name;
command.Paramet ers.Add( pName );
SqlParameter pData = new SqlParameter( "@data", SqlDbType.Image );
pData.Value = imageData;
command.Paramet ers.Add( pData );
try
{
connection.Open ();
int numRowsAffected = command.Execute NonQuery();
}
finally
{
connection.Clos e();
}
}
/****/

and on client side:

/****/
remoteService.S erviceSoapClien t srv = new remoteService.S erviceSoapClien t();
Image image = Image.FromFile( @"c:\myimage.bm p");
using(MemoryStr eam stream = new MemoryStream())
{
image.Save( stream );
byte[] buffer = steam.ToByteArr ay();
srv.SaveImage( "myimage", buffer );
}
/****/

My questions: is this good practice? Is there a better way to do it?

Thanks in advance. Sorry the long post.

Marco
Mar 20 '08 #1
2 1849
Looks like you've got the right idea if you want to do it that way.
You mentioned that you have workstations using this telling me its
potentially an internal app, if thats the case what we did when I had
a similar issue was save the image/file to a shared directory on the
server and put the path to the image in the database.
Mar 20 '08 #2
Right bow, I'm using a shared folder on the server. The problem is that
workstations aren't connected to a domain controler (windows home editons
versions only), and the first time workstations try to access server, thay
must authenticate.

Well, "regular" computer users, can't deal well with this, as you can
imagine.

"cfps.Christian " <ge*******@otc. eduescreveu na mensagem
news:d1******** *************** ***********@q78 g2000hsh.google groups.com...
Looks like you've got the right idea if you want to do it that way.
You mentioned that you have workstations using this telling me its
potentially an internal app, if thats the case what we did when I had
a similar issue was save the image/file to a shared directory on the
server and put the path to the image in the database.

Mar 20 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1776
by: TheTenor | last post by:
I have a page with a graphic. I want to be able to define the graphics such that it is not saved when the viewer saves the page to his local drive. I'm trying to avoid having a seperate folder created just for the graphic when the page is saved. The page is an asp page that is used to access a database record. I have the page title convey the record name so that the user can save the page and it will be saved with the record name. I just...
1
1633
by: MIchael McDowell | last post by:
Anyidea how this might be done using and XML Web Service and the XMLSerialzation class? A pointer to an online example would be deeply appreciated. Thankyou in advance, Michael McD
3
2461
by: sameer | last post by:
Hi all, ..net framwork 1.1 sql server 2000 I have a vb.net winforms application using webservices\ remoting to upload documents\ images to the webserver and i am gong to store them in the sql server 2000 database and before these are saved to the database client wants me to scan them for any kind of viruses i.e do a virus scan, how can i do that, have any body done this before. if it was a matter of
0
2211
by: sameer | last post by:
Hi all, ..net framwork 1.1 sql server 2000 I have a vb.net winforms application using webservices\ remoting to upload documents\ images to the webserver and i am gong to store them in the sql server 2000 database and before these are saved to the database client wants me to scan them for any kind of viruses i.e do a virus scan, how can i do that, have any body done this before. if it was a matter of
6
6456
by: Mark Denardo | last post by:
My question is similar to one someone posted a few months back, but I don't see any replies. Basically I want to be able to have users upload photos and save them in a database (as byte data) and be able to load them to an image webcontrol, but system.web.ui.webcontrols.image only seems to have a control to load the image from a URL. There's no way to load this directly without saving the image as a file and then using...
3
2474
by: pozze | last post by:
Hi, I've just made the change from ASP to .net. I have a file (code below) that saves a user submitted file to a MS SQL 2005 database. It collects the file name, file size, file type, and lastly the binary data for the file. I can sucessfully take the files out of the databse again and display them in a data grid. I would like to resize the submitted file to a fixed size (say 180 x 120) before I upload it to the database and do this without...
2
1291
by: carj2ee | last post by:
I trying to write a program that will go to a website and get all the images and then save then on to a local drive. I am using a mshtml.HTMLImg variable and then directcasting the web page to mshtml document, and then retriving all images. I am able to retrieve all the names of the images. How do I store these images on to the local drive? Any help is appreciated. Thanks.
6
8071
by: Eddie | last post by:
Hi all, I am displaying a number of reports, and giving the users an option to display them on the web or download them to Excel. If they want the Excel file, I just use the PHP header command to change the Content- Type and Content-Disposition headers, and essentially print the same report, and it's done. That works fine. But in some reports on the web I need to show images. The web part is fine, but I'm having a tough time...
10
7443
by: Nathan Sokalski | last post by:
I am using ASP.NET 2.0, and need to know how to save and use an image that is stored in an SQL Server image datatype. How can I do this using ASP.NET? Thanks.
0
9687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10485
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10252
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4141
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.