title: Error while using Keyword Query object in asp.net application for search in sharepoint
body: <p>I am trying to use Keyword Query object in asp.net application. </p>
  
  <h2>I wrote this code :</h2>
  
  <p>Namespace : using System.Data.SqlClient;
              using Microsoft.SharePoint;
              using Microsoft.SharePoint.Search;
              using Microsoft.SharePoint.Search.Query;</p>
  
  <p>Page load event:
              GridView grd = new GridView();
              DataTable dt = new DataTable();
          KeywordQuery qRequest = new KeywordQuery("<a href="http://server/ril" rel="nofollow noreferrer">http://server/ril</a>");
          qRequest.QueryText = "RILLIB";
          ResultTableCollection resTableCollect = qRequest.Execute();
          ResultTable resTable = resTableCollect[ResultType.RelevantResults];
          DataTable dtTable = new DataTable();
          dtTable.Load(resTable, LoadOption.OverwriteChanges);
          grd.DataSource = dtTable;
          grd.DataBind();</p>
  
  <h2>        Page.Controls.Add(grd);</h2>
  
  <p>Ok? Whe i run it gives me error : <strong>Exception from HRESULT: 0xC0041228</strong></p>
  
  <p><strong>When i saw Logs i found these lines. What the error exactly ? how can i remove that?</strong></p>
  
  <p>Event Type: Error
  Event Source: Office SharePoint Server
  Event Category: Office Server Shared Services 
  Event ID: 6481
  Date:  05/11/2009
  Time:  6:12:25 PM
  User:  N/A
  Computer: SERVER
  Description:
  Application Server job failed for service instance Microsoft.Office.Server.Search.Administration.SearchServiceInstance (41fdea47-166f-4d9f-9cd0-4f3dd0f5cd5b).</p>
  
  <p>Reason: Access to the path 'C:\WINDOWS\system32\drivers\etc\HOSTS' is denied.</p>
  
  <p>Techinal Support Details:
  System.UnauthorizedAccessException: Access to the path 'C:\WINDOWS\system32\drivers\etc\HOSTS' is denied.
     at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
     at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
     at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
     at System.IO.StreamWriter.CreateFile(String path, Boolean append)
     at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize)
     at System.IO.StreamWriter..ctor(String path, Boolean append)
     at System.IO.FileInfo.CreateText()
     at Microsoft.Search.Administration.Security.HOSTSFile.CleanupDedicatedGathering(Hashtable HOSTSFileMappings, StringBuilder HOSTSComments, IEnumerable obsoleteHosts, String dedicatedName, Boolean isDirty)
     at Microsoft.Search.Administration.Security.HOSTSFile.ConfigureDedicatedGathering(SearchServiceInstance searchServiceInstance, SPServer dedicatedWebFrontEndServer, IList`1 previousWebApplicationHostNames)
     at Microsoft.Office.Server.Search.Administration.SearchServiceInstance.SynchronizeDefaultContentSource(IDictionary applications)
     at Microsoft.Office.Server.Search.Administration.SearchServiceInstance.Synchronize()
     at Microsoft.Office.Server.Administration.ApplicationServerJob.ProvisionLocalSharedServiceInstances(Boolean isAdministrationServiceJob)</p>
  
  <p>For more information, see Help and Support Center at <a href="http://go.microsoft.com/fwlink/events.asp" rel="nofollow noreferrer">http://go.microsoft.com/fwlink/events.asp</a>.</p>