Reputation: 417
i want to store a word documents (.doc) in the database and i need to provide search over a collection of Word documents and highlight the words too.
I m using VS2005 --> ASP.NET, C#.NET, SQL Server.
Upvotes: 0
Views: 4205
Reputation: 21938
you can store it in DB as a BLOB (Binary Large OBject).
Something similar would work
string filePath = "";
string connectionString = "";
FileStream stream =
new FileStream(filePath, FileMode.Open, FileAccess.Read);
BinaryReader reader = new BinaryReader(stream);
byte[] file = reader.ReadBytes((int)stream.Length);
reader.Close();
stream.Close();
SqlCommand command;
SqlConnection connection = new SqlConnection(connectionString);
command =
new SqlCommand("INSERT INTO FileTable (File) Values(@File)", connection);
command.Parameters.Add("@File", SqlDbType.Binary, file.Length).Value = file;
connection.Open();
command.ExecuteNonQuery();
have a look at this post for bit more details :
Upvotes: 2
Reputation: 31383
Is your site public? A good unconventional solution is to use Google. Type into google:
site:www.yoursite.com filetype:doc searchTerm
Here is an example. Notice the View HTML link hightlights the text. WhiteHouse.gov OMB Search
If you want to get fancy, you could use the WebRequest object to make the request to Google on the server, and then parse out the response to just display the ViewHtml links on your page.
Upvotes: 0
Reputation: 656
You can store the documents as BLOBs as described above. You then need some way of indexing the contents so you can search.
You could be crude and extract the contents of the Word document as text, store this along with the document and then query this new column using the keywords.
This is not going to be particuarly quick or efficent though. It looks as though Full-Text Indexing may do the trick: http://www.codeproject.com/KB/architecture/sqlfulltextindexing.aspx Apparently Office documents can be indexed.
When a keyword is entered you can then query the full-text index, find matching documents and then open the documents and highlight the words using either the Office Primary Interop assesmbiles or VSTO.
Upvotes: 1