开发者

To store and search word documents using C#.NET,ASP.NET

i want to store a word documents (.doc) in the database and i need to provide sear开发者_开发百科ch over a collection of Word documents and highlight the words too.

I m using VS2005 --> ASP.NET, C#.NET, SQL Server.


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 :

    How to store word documents in Database using C#


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜