How to store/retrieve a file in a database ...........
-
How to store a file(doc/txt/jpeg) in a database(sql server/access) and how to retrieve it from the database using .net. Can u please send me the step by step approach to achieve this.
-
save the url of the files in database and design a page that reads the url. It's easy....... if you wants to store the files in the databae that's going to be tricky but not impossible....... If you want more help plz do say so. I have done this. leo
thanks for the info.Please confirm me the following. -- I need to store the path(virtual) path of the file(?) -- i need to access the path of the file from the databaseand do the file operations like any other file(?) if it is not so please explain me how to do that and the classes involved in it. thanks, jyothi
-
How to store a file(doc/txt/jpeg) in a database(sql server/access) and how to retrieve it from the database using .net. Can u please send me the step by step approach to achieve this.
The following ASPX file reads and displays an image from the Pubs database that comes with Microsoft SQL Server. <%@ Import Namespace="System.Data.SqlClient" %> <%@ Import Namespace="System.Drawing" %> <%@ Import Namespace="System.Drawing.Imaging" %> <%@ Import Namespace="System.IO" %> void Page_Load(object sender, System.EventArgs e) { MemoryStream stream = new MemoryStream (); SqlConnection connection = new SqlConnection ("server=localhost;database=pubs;uid=sa;pwd="); try { connection.Open (); SqlCommand command = new SqlCommand ("select logo from pub_info where pub_id='0736'", connection); byte[] image = (byte[]) command.ExecuteScalar (); stream.Write (image, 0, image.Length); Bitmap bitmap = new Bitmap (stream); Response.ContentType = "image/gif"; bitmap.Save (Response.OutputStream, ImageFormat.Gif); } finally { connection.Close (); stream.Close (); } } ENJOY MAADE
-
How to store a file(doc/txt/jpeg) in a database(sql server/access) and how to retrieve it from the database using .net. Can u please send me the step by step approach to achieve this.
/* adds image name specified as parameter in Image table (Database GDP) Stru: Images ImageID int IDENTITY FullName varchar(50) ImageData image */ using System; using System.IO; using System.Data.SqlClient; class StoreImage { public void AddImageToDatabase(String strImageName) { SqlConnection cnObj = new SqlConnection("Data Source=tilsrv-dev1;Initial Catalog=GDP;User ID=sa;password=;"); FileStream stream = new FileStream(strImageName, FileMode.Open); byte[] bytBlob = new byte[stream.Length]; stream.Read(bytBlob, 0, (int)stream.Length); stream.Close(); try { cnObj.Open(); SqlCommand cmdInsertImage = new SqlCommand("INSERT INTO Images(FullName, ImageData) VALUES('" + strImageName + "', @Img)", cnObj); cmdInsertImage.Parameters.Add("@Img", bytBlob); cmdInsertImage.ExecuteNonQuery(); } catch(SqlException e) { Console.WriteLine(e.Message); } finally { cnObj.Close(); } } public static void Main(String[] args) { StoreImage obj; if(args.Length == 0) Console.WriteLine("USAGE: StoreImage "); else { obj = new StoreImage(); obj.AddImageToDatabase(args[0]); } } } ENJOY MAADE.