Uploading Docs Into Sql Server

G

Guest

Can someone offer or point me to some sample code or advice on how to upload a document from a web page and store it into a SQL Server image field? And then reverse the process and serve up the file from the database when requested through a web page...

Thanks.

Jerry
 
S

Superman

Jerry,

1. Uploading is simple for the actual file uploading piece.

Use the <asp:htmlfileinput /> control and when the page posts use the
..PostedFile.SaveAs(stream) method to save it. Use a SqlCommand and add
a parameter, set it's type to SqlDbType.Image.

2. Retrieving the data is relatively simple, fill your dataset and
extract the column as you would any other column. Cast it to whatever
you need...

variable = (byte[])dataset.Tables[0][x];

HTH,

-Brenton MCSD.NET
 
S

Steven Cheng[MSFT]

Hi Jerry,

For Uploading file in ASP.NET, there are many tech article describing this:

#How to upload a file to a Web server in ASP.NET by using Visual Basic .NET
http://support.microsoft.com/kb/323245/en-us

#ASP.NET 2.0 FileUpload Server Control
http://www.codeguru.com/dbfiles/get_avatar.php?id=183439

Also, the following article has demonstrate store the uploaded file content
into database binary data table column:

#File Upload with ASP.NET
http://www.codeproject.com/aspnet/fileupload.asp


In addition, for reading and retrieveing binary/image data in SQL Server,
they're pure ADO.NET data accessing tasks and here are some good article
demonstrate this:


#Storing and Retrieving Images from SQL Server using Microsoft .NET
http://www.codeproject.com/cs/database/ImageSaveInDataBase.asp

#Utilize ADO.NET and C# to work with BLOB data
http://builder.com.com/5100-6371_14-5766889.html


Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

hello,
if you're using C# 2.0 then try the web control FileUpload which has SaveAs
method...
hope it'll help
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top