C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Images »

Retrieving Image from SQL Server


Posted Date: 07 Jul 2009    Resource Type: Code Snippets    Category: Images
Author: Anil Kumar PandeyMember Level: Diamond    
Rating: 1 out of 5Points: 10 (Rs 5)



hi,

Please check out this code for retrieving the image from the sql server, first get the image field data in a data reader and from there we can convert the data into a BYTE array, using that array the file can be created..

have a look



byte[] file = SqlConvert.ToByteArray(dr["FileImage"]);

string fileName = SetupFileName(SqlConvert.ToString(dr["FileName"]));

string filePath = System.Environment.CurrentDirectory + “\\myFiles\\” + fileName;

FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);

BinaryWriter bw = new BinaryWriter(fs);

bw.Write(file);

bw.Flush();

bw.Close();

fs.Close();


Happy Coding!!!! :)

Thanks
Anil Kumar Pandey
System Architect
Green Point Technology (India) Ltd.
Mumbai, Maharshtra



Responses

Author: R.Jaya kumar (JK)    07 Jul 2009Member Level: Diamond   Points : 1
hi

anil

chenage this line vb.net here

Dim file() As Byte = SqlConvert.ToByteArray(dr("FileImage"))
Dim fileName As String = SetupFileName(SqlConvert.ToString(dr("FileName")))




Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Retrieving image from Sql server  .  Image upload  .  Image Processing  .  Anil Pandey  .  Anil Kumar Pandey  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Saving the image file in SQL server
Previous Resource: Resize the image
Return to Discussion Resource Index
Post New Resource
Category: Images


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use