Click here to Skip to main content
15,908,264 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is anybody can help me to do the coding to browse and save the image in visualstudio2010 and storing the image to sql server2008?
Posted
Updated 8-Nov-12 17:31pm
v2

Use this link
Store Images in SQL Server[^]
 
Share this answer
 
//to convert ur attachment into bytearray
byte[] Attachmnt;
tbUpload.Text = openFileDialog1.SafeFileName;
FilePath = openFileDialog1.FileName;
 if (openFileDialog1.FileName != null)                        
{     
System.IO.FileStream fs = new System.IO.FileStream(FilePath, System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite);
System.IO.BinaryReader binaryReader = new System.IO.BinaryReader(fs);
long byteLength = new System.IO.FileInfo(FilePath).Length;
Attachmnt = binaryReader.ReadBytes((Int32)byteLength);
fs.Close();
fs.Dispose();
binaryReader.Close();
}     


 public class Document   
       {      
        public byte[] DocContent { get; set; }
       }
//on the upload event
Document objDoc = new Document();
 objDoc.DocContent = Attachmnt;
ResumeData_ = objDoc.DocContent;
Submit();//my function to save resumedata at database where column type is image
                pre>
 
Share this answer
 
v2
Comments
StackQ 8-Nov-12 1:59am    
as here i m selecting .doc file through openfiledialog,u can select image file instead it.It will work for any type file.Hope it will help u
You can save the byte array in database. For this you need to convert the image in byte array.
 
Share this answer
 
convert the image into bytes using this
byte[] doc=FileUploadimg.Filebytes;

and save it to database. the datatype should be image in database
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900