C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » Sharepoint »

Error while using Keyword Query object in asp.net application for search in sharepoint


Posted Date: 05 Nov 2009      Posted By: Red Swan      Member Level: Gold     Points: 1   Responses: 4



I am trying to use Keyword Query object in asp.net application.
I wrote this code :

Namespace :
using System.Data.SqlClient;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Search;
using Microsoft.SharePoint.Search.Query;

Page load event:
GridView grd = new GridView();
DataTable dt = new DataTable();
KeywordQuery qRequest = new KeywordQuery("http://server/ril"); 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();
Page.Controls.Add(grd);

Ok?
When i run it gives me error : Exception from HRESULT: 0xC0041228

When i saw Logs i found these lines. What the error exactly ? how can i remove that?


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).
Reason: Access to the path 'C:\WINDOWS\system32\drivers\etc\HOSTS' is denied.
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, SECURITYATTRIBUTES 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)
For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.






Responses

Author: Rajapandian    05 Nov 2009Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

Hi,

For Search web part we used below code. You can try that.

Namespaces:
---------------
using System;
using System.Text;
using System.Drawing;
using System.Data;
using System.Web.UI.WebControls;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint.Search;
using Microsoft.SharePoint.Search.Query;
using System.Web;
using System.Web.UI;
using System.Text.RegularExpressions;

Function:(Pass the search string to the first function)
---------
public void keywordQueryExecute(string strQueryText)
{

using (SPSite _SPSite = new SPSite("http://IP ADDRESS HERE/sites/SITE NAME HERE/"))
{
using (FullTextSqlQuery _FullTextSqlQuery = new FullTextSqlQuery(_SPSite))
{
_FullTextSqlQuery.StartRow = 0;
_FullTextSqlQuery.HighlightedSentenceCount = 3;
_FullTextSqlQuery.KeywordInclusion = KeywordInclusion.AnyKeyword;
_FullTextSqlQuery.ResultTypes = ResultType.RelevantResults;
_FullTextSqlQuery.RowLimit = 5000;
_FullTextSqlQuery.TrimDuplicates = true;
_FullTextSqlQuery.EnableStemming = false;
_FullTextSqlQuery.IgnoreAllNoiseQuery = true;
_FullTextSqlQuery.SiteContext = new Uri(_SPSite.Url);

if (SPSecurity.AuthenticationMode != System.Web.Configuration.AuthenticationMode.Windows)

_FullTextSqlQuery.AuthenticationType = QueryAuthenticationType.PluggableAuthenticatedQuery;

else

_FullTextSqlQuery.AuthenticationType = QueryAuthenticationType.NtAuthenticatedQuery;

StringBuilder sbFullTextSqlQuery = new StringBuilder(string.Empty);
sbFullTextSqlQuery.Append("SELECT ");
sbFullTextSqlQuery.Append(" FileExtension,Title,Description,HitHighlightedSummary,Path,Author,Size,LastModifiedTime ");
sbFullTextSqlQuery.Append("FROM ");
sbFullTextSqlQuery.Append(" SCOPE() ");
sbFullTextSqlQuery.Append("WHERE ");
sbFullTextSqlQuery.Append(" Site= ");
sbFullTextSqlQuery.Append(" '" + _SPSite.Url.ToString() + "' ");
sbFullTextSqlQuery.Append(" AND ");
sbFullTextSqlQuery.Append(" ( FREETEXT (DefaultProperties, '" + strQueryText + "') ");
sbFullTextSqlQuery.Append(" OR ");
sbFullTextSqlQuery.Append(" CONTAINS (*, '\"" + strQueryText + "*" + "\"')) ");
sbFullTextSqlQuery.Append(" ORDER BY ");
string strSort = " Rank Desc";
sbFullTextSqlQuery.Append(strSort);
//sbFullTextSqlQuery.Append(" Rank Desc");

_FullTextSqlQuery.QueryText = sbFullTextSqlQuery.ToString();
try
{

ResultTableCollection resultTables = _FullTextSqlQuery.Execute();


if ((int)ResultType.RelevantResults != 0)
{

ResultTable tblResult = resultTables[ResultType.RelevantResults];

if (tblResult.TotalRows == 0)
{
lblQueryResult.Text = "No Search Results Returned.";
}
else
{
ReadResultTable(tblResult);
lblQueryResult.Text = "";
}
}
}
catch (Exception Ex)
{
lblQueryResult.Text = Ex.Message;
}

}
}
}

public void ReadResultTable(ResultTable rt)
{
// Create a DataSet and load the returned ResultTable into it.
DataTable relResultsTbl = new DataTable();
relResultsTbl.TableName = "Relevant Results";
DataSet ds = new DataSet("resultsset");
ds.Tables.Add(relResultsTbl);
ds.Load(rt, LoadOption.OverwriteChanges, relResultsTbl);

// Add the results to the DataGrid.
fillResultsGrid(ds);
}





Finally the DataSet ds will have the result.



Author: Red Swan    05 Nov 2009Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

Thanks ist working ..... gr8 thanks


Author: Red Swan    06 Nov 2009Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

hi I used above code , it is working fine. but when i specify my site & in query add some new columns then it is giving me exception as:

Property doesn't exist or is used in a manner inconsistent with schema settings

What i have to to to fix it ?



Author: Rajapandian    06 Nov 2009Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

Hi,

We are using WSS. In WSS we can get only particular properties. I don't know about MOSS. But I come to know that MOSS has a UI for managing and creating managed properties. You can get to this via Shared Service Provider administration --> Search Settings --> Metadata property mappings. Here you can see all the managed properties available to query against. They will only work if you have "crawled properties" mapped to them.

from the below link

http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/f98bfe76-0750-4ad0-ac1b-0c171d59a3e6



Post Reply
You must Sign In to post a response.
Next : How to programe on Search object model of sharepoint
Previous : Sharepoint number field without commas
Return to Discussion Forum
Post New Message
Category: Sharepoint

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use