none
How to store .doc and image file in database using c# RRS feed

  • Question

  • private void FileStream_PUT(string filepath)

           {

               byte[] file;

               FileStream fs = new FileStream(filepath, FileMode.Open, FileAccess.Read);

               BinaryReader br = new BinaryReader(fs);

               file = br.ReadBytes((int)fs.Length);

               SqlCommand cmd = new SqlCommand("insert into docfile values(@name,@file)", con);

               cmd.Parameters.Add("name", SqlDbType.VarChar, 50).Value = textBox1.Text;

               cmd.Parameters.Add("file", SqlDbType.VarBinary, file.Length).Value = file;

               con.Open();

               int a = cmd.ExecuteNonQuery();

               if (a > 0)

                   MessageBox.Show("Inserted");

               con.Close();

           }


    • Moved by CoolDadTx Sunday, December 8, 2013 4:41 PM ADO.NET related
    • Changed type Fred BaoModerator Monday, December 16, 2013 9:45 AM It is a question
    Sunday, December 8, 2013 1:32 AM

Answers

  • Seriously, this like the 6th post where you describe how something is done without any question being asked, by you or others. Just code that propably works perfectly.

    This forum is for people who have question and need help with problems. You do not ask or answer any questions.
    You are quickly approaching the point where your posts can be considered spam. Stop doing that please.


    Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2 Please mark post as helpfull and answers respectively.

    Sunday, December 8, 2013 7:37 AM
  • Answer for your question is in your question :) Look at line where you put your file data to DB :) there is one little word saying how your file will be stored in DB :)
    Sunday, December 8, 2013 2:11 PM
  • Hello,

    We can store the data in binary and use full text search to interpret the binary data and extract the textual information: .doc, .txt, .xls, .ppt, .htm. The extracted text is indexed and becomes available for querying.

    For more information look at this:

    http://technet.microsoft.com/en-us/library/ms142499(SQL.90).aspx

    Or the other thing that I could suggest is probably storing keywords in the database and then linking the same to file in the fileshare.

    Here is an article discussing abt using a FileStream and a database:

    http://blogs.msdn.com/b/manisblog/archive/2007/10/21/filestream-data-type-sql-server-2008.aspx

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, December 9, 2013 2:16 AM
    Moderator

All replies

  • Seriously, this like the 6th post where you describe how something is done without any question being asked, by you or others. Just code that propably works perfectly.

    This forum is for people who have question and need help with problems. You do not ask or answer any questions.
    You are quickly approaching the point where your posts can be considered spam. Stop doing that please.


    Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2 Please mark post as helpfull and answers respectively.

    Sunday, December 8, 2013 7:37 AM
  • Answer for your question is in your question :) Look at line where you put your file data to DB :) there is one little word saying how your file will be stored in DB :)
    Sunday, December 8, 2013 2:11 PM
  • Hello,

    We can store the data in binary and use full text search to interpret the binary data and extract the textual information: .doc, .txt, .xls, .ppt, .htm. The extracted text is indexed and becomes available for querying.

    For more information look at this:

    http://technet.microsoft.com/en-us/library/ms142499(SQL.90).aspx

    Or the other thing that I could suggest is probably storing keywords in the database and then linking the same to file in the fileshare.

    Here is an article discussing abt using a FileStream and a database:

    http://blogs.msdn.com/b/manisblog/archive/2007/10/21/filestream-data-type-sql-server-2008.aspx

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, December 9, 2013 2:16 AM
    Moderator