YAFLogo

john55
  • john55
  • 53% (Neutral)
  • YAF Forumling Topic Starter
11 years ago
Hi there,

Running YAF 2.0 on .NET 4.0.

I'm trying to run a YAF search outside of a regular YAF page (inheriting from System.Web.UI.Page). Search runs okay but line where search results get converted to an array is giving a syntax error:

'search_results' does not contain a definition for 'Get' and the best extension method overload 'YAF.Types.Interfaces.IServiceLocatorExtensions.Get(YAF.Types.Interfaces.IHaveServiceLocator)' has some invalid arguments

any ideas?

Thanks


using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using YAF.Core.Data;
using YAF.Core.Extensions;
using YAF.Core.Services;
using YAF.Types.Extensions;
using YAF.Types.Interfaces.Data;
using nStuff.UpdateControls;
using YAF.Classes;
using YAF.Classes.Data;
using YAF.Core;
using YAF.Types;
using YAF.Types.Constants;
using YAF.Types.Interfaces;
using YAF.Utilities;
using YAF.Utils;

using System.Collections.Generic;
using System.Runtime.CompilerServices;

using System.Linq;
using System.Text.RegularExpressions;


public partial class search_results : System.Web.UI.Page
{
private void searchBindData(string searchString)
{
var sw = (SearchWhatFlags)Enum.Parse(typeof(SearchWhatFlags), "2"Wink;
var sfw = (SearchWhatFlags)Enum.Parse(typeof(SearchWhatFlags), "2"Wink;
int forumId = 0;

var context = new CompleteSearchContext(
searchString,
"",
sfw,
sw,
3,
1,
100, false, true,
forumId);

//following line gives syntax error
var searchResults = this.Get<ISearch>().Execute(context).ToArray();
Sponsor
tha_watcha
  • tha_watcha
  • 100% (Exalted)
  • YAF.NET Project Lead 🤴 YAF Version: 4.0.1 BETA
11 years ago
Change the line to....

var searchResults = YafContext.Current.Get<ISearch>().Execute(context).ToArray();
john55
  • john55
  • 53% (Neutral)
  • YAF Forumling Topic Starter
11 years ago
Cool. Thanks. One more question...

In \YetAnotherForum.NET\pages\search.ascx there is

<%# HtmlEncode(Container.DataItem.ToType().Topic) %>

which I changed to following to run in my page inheriting from System.Web.UI.Page

<%# Server.HtmlEncode(YAF.Types.Extensions.ObjectExtensions.ToType(Container.DataItem).Topic) %>

This works fine for Topic, TopicId, etc however .Message doesn't display the message it returns a 0-length string.

How do I display the message in the YAF search results on a page inheriting from System.Web.UI.Page?

Thanks!