views:

337

answers:

5

I am trying to do a search on a scope in SharePoint. I see this error.

My code:

using (SPSite siteCollection = new SPSite("http://sp:25000/"))
{
    // create a new FullTextSqlQuery class - use property intializers to set query
    FullTextSqlQuery query = new FullTextSqlQuery(siteCollection);
    query.QueryText = "SELECT Title" + " from scope() where \"scope\" ='ArticleScope'" + "and Contentclass = 'STS_ListItem_GenericList'";
    query.ResultTypes = ResultType.RelevantResults;
    query.RowLimit = Int32.MaxValue;
    query.TrimDuplicates = true;
    query.EnableStemming = false;
    query.IgnoreAllNoiseQuery = true;
    query.KeywordInclusion = KeywordInclusion.AllKeywords;
    query.Timeout = 0x2710;
    query.HighlightedSentenceCount = 3;
    query.SiteContext = new Uri(siteCollection.Url);
    // execute the query and load the results into a datatable
    ResultTableCollection queryResults = query.Execute();
    ResultTable queryResultsTable = queryResults[ResultType.RelevantResults];
    DataTable queryDataTable = new DataTable();
    queryDataTable.Load(queryResultsTable, LoadOption.OverwriteChanges);
}
A: 

How are you accessing SharePoint? From the screenshot it seems as if you have a Web Page running in a Non-SharePoint IIS Web Application on a SharePoint server, which is not supported (Referencing the Microsoft.SharePoint Assembly from ANY Application running outside SharePoint is officially unsupported, even though some features may run)

What happens if you run this code from within SharePoint (i.e. in a Web Part)?

Michael Stum
Thanks for the tip Michael. I will try to create a web part. I am now running it from a non SharePoint Web Application.
Pradeep007
I tried to create a web part but am facing the same problem!!!I have removed the space before "and"Thank you for pointing that.
Pradeep007
What is the URL for the SPSite you are using in your web part? Could you add the code you put in the web part to your question?
Kit Menke
A: 

I can't see the error as it's blocked by my proxy. However my guess is that you should have a space before the and. (Is there any reason why this isn't one long string?)

'ArticleScope'" + "and
                   ^

If not can you please copy and paste the error into your question.

Alex Angas
A: 

You are missing a space before the and.

THis means

where \"scope\" ='ArticleScope'" + "and Contentclass = 'STS_ListItem_GenericList'

becomes

where \"scope\" ='ArticleScope'and Contentclass = 'STS_ListItem_GenericList'

'ArticleScope' and AND are concatenated: 'ArticleScope'and

Colin
A: 

Are you using Microsoft SharePoint Server 2007 (MOSS)? Or do you only have Windows SharePoint Services 3.0 (WSS)? From what I saw, Scopes are a MOSS-Feature not available in WSS, but I'm guessing a bit.

Michael Stum
Michael, I am using MOSS 2007.
Pradeep007
+1  A: 

Fixed!!!

Used this link

The code I have used:

 using (SPSite siteCollection = new SPSite("http://sp:25000/"))
        {
            Microsoft.Office.Server.Search.Query.FullTextSqlQuery query = new Microsoft.Office.Server.Search.Query.FullTextSqlQuery(siteCollection);
            query.QueryText = "SELECT Title from scope() where \"scope\" ='All Sites' and Contentclass = 'STS_ListItem_GenericList'";
            query.ResultTypes = Microsoft.Office.Server.Search.Query.ResultType.RelevantResults;
            query.RowLimit = Int32.MaxValue;
            query.TrimDuplicates = true;
            query.EnableStemming = false;
            query.IgnoreAllNoiseQuery = true;
            query.KeywordInclusion = Microsoft.Office.Server.Search.Query.KeywordInclusion.AllKeywords;
            query.Timeout = 0x2710;
            query.HighlightedSentenceCount = 3;
            query.SiteContext = new Uri(siteCollection.Url); 
            query.AuthenticationType = Microsoft.Office.Server.Search.Query.QueryAuthenticationType.NtAuthenticatedQuery;
            Microsoft.Office.Server.Search.Query.ResultTableCollection queryResults = query.Execute();
            Microsoft.Office.Server.Search.Query.ResultTable queryResultsTable = queryResults[Microsoft.Office.Server.Search.Query.ResultType.RelevantResults];
            DataTable queryDataTable = new DataTable();
            queryDataTable.Load(queryResultsTable, LoadOption.OverwriteChanges);
        }

Thanks for your support.

Pradeep007