Wednesday, March 7, 2012

needed sql script to convert binary content

Hi all,

how r u everyone, guys i need a help, i have a interface in my application, adding attachments to issues, ie users can attach a file for a particular issue and if anyone have to view they ve click a link and it will download.

iam using filestream and binaryreader concept in that, ie read the file using filestream and then use binaryreader.readbytes method to convert it into byte array and store it in the database in a column with a image datatype as a binary content.

FileStream oImg;
BinaryReader oBinaryReader;
byte[] oImgByteArray;

oImg = new FileStream(sFilePath,FileMode.Open,FileAccess.Read);
oBinaryReader = new BinaryReader(oImg);
oImgByteArray = oBinaryReader.ReadBytes((int)oImg.Length);
oBinaryReader.Close();
oImg.Close();

this is the code iam using.

when i use this its taking so much of time to get uploaded. so what i thought of doing is save the file in a specific folder using some postedfile.saveas(not sure of syntax) and when the user wants to view the file they can just download the file. i can do this by googling but what i want is wat abt the existing attachments in the database. so i need a help to do this......

is it possible to create a query to read the files and convert it into original file and save it in the specific folder or do i ve to create a simple interface to create do it manually , pls someone help me what to do .....

thanks in advance.

waiting for a reply soon

Note: any unclear statement in my question kindly reply me

Wishes n Regards

Venkat.

Hi,

Based on my understanding, I understand that you're trying to pass the files in a specific folder to the client.

Yes, I think it is possible to do this. But we cannot save the binary content of the file in database. In your database, you can only store the path of the file, then just use the following code to push to client.

String filePath = Server.MapPath(PathOfFileFromDatabase);
System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath);
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", String.Format(@."attachment;filename=\""{0}\""", filePath));
Response.AddHeader("Content-Length", fileInfo.Length.ToString());
Response.WriteFile(filePath);
Response.End();

HTH. If this does not answer your question, please feel free to mark the post as Not Answered and reply. Thank you!

|||

Hi,Thanks for the reply, it was useful for me , but still wat iam looking for is , is it possible to do the same as a sql query , i mean i shld run a query or a stored procedure in query analyser that shld do same without using an interface , is it possible ?

is it possible to read a image from a db table using a sql query ?

Thanks in advance

Wishes n Regards

No comments:

Post a Comment