locked
Using the AutoCompleteExtender within a SharePoint page RRS feed

  • Question

  • I'm trying to use the AutoCompleteExtender control within a SharePoint page without using a custom webservice. (see http://allwrong.wordpress.com/2007/03/13/ms-ajax-autocomplete-extender-using-a-page-method/)

    However, when adding EnablePageMethods=”true” to the ScriptManager within the page, I get the following error;

    "System.Web.HttpException: Directory 'C:\inetpub\wwwroot\wss\VirtualDirectories\business\ict\_catalogs\masterpage' does not exist. Failed to start monitoring file changes"

    Removing the attribute solves the problem. How do I stop this from occuring? I've already tried using a web service and deploying that to the _vti_bin folder but all I got were 401 errors which I'm guessing is due to authentication.
    Monday, November 30, 2009 3:24 PM

Answers

  • I've never tried to use an AutoCompleteExtender on a SharePoint site page this way.  Not sure if it's possible.  I think what you'll need to do is write a custom SharePoint-compatible web service that provides the server-side responses.  This would then get deployed into the _vti_bin folder.  I know you tried this, but it may be due to the special way in which .asmx web pages must be deployed into SharePoint. 

    You can see this article I wrote a while back which discusses how to write a deploy a custom web service in SharePoint.  The relevent section in the article is Deploying our Web Service
    http://www.synergyonline.com/blog/blog-moss/Lists/Posts/Post.aspx?ID=17

    In a class I teach, I develop a web part that use the AutoCompleteExtender to return a list of matching contact names.  Here is the web service portion of that example, so you can see the syntax I used.  Your logic, of course, will be different.

    I can send you the client part, but this will be different that what you're doing since mine was based on a web part.  Incidentally, I do have a script manager on the page (it is required), but I do not use the EnablePageMethods attribute and it works just fine.

    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    [ScriptService]
    public class AJAXDemos : System.Web.Services.WebService
    {
        [WebMethod]
        public string[] GetContacts(string prefixText, int count)
        {
            //Get our current web context
            SPWeb web = SPContext.GetContext(HttpContext.Current).Web;
            int rowCount = count;
    
            //Reference the Contacts list
            SPList list = web.Lists["Contacts"];
    
            //Create an SPQuery to return all contacts sorted by last name
            SPQuery query = new SPQuery ();
            query.Query = "<Where><BeginsWith><FieldRef Name='Title'/><Value Type='Text'>" + prefixText + "</Value></BeginsWith></Where><OrderBy><FieldRed Name='Title'/></OrderBy>";
    
            //Execute query    
            SPListItemCollection items = list.GetItems (query);
    
            //set the count of rows appropriately
            if (items.Count < rowCount)
                rowCount = items.Count;
    
            //declare our array to hold the contact list
            string[] arrContacts = new string[rowCount];
    
            //Store our SPListItemCollection into string array
            for (int i = 0; i < rowCount; i++)
            {
                arrContacts[i] = items[i]["Last Name"].ToString();
            }
            return arrContacts;
        }
    }
    



    Randy - http://sharepointhawaii.com/randywilliams
    Tuesday, December 1, 2009 1:20 PM

All replies

  • I've never tried to use an AutoCompleteExtender on a SharePoint site page this way.  Not sure if it's possible.  I think what you'll need to do is write a custom SharePoint-compatible web service that provides the server-side responses.  This would then get deployed into the _vti_bin folder.  I know you tried this, but it may be due to the special way in which .asmx web pages must be deployed into SharePoint. 

    You can see this article I wrote a while back which discusses how to write a deploy a custom web service in SharePoint.  The relevent section in the article is Deploying our Web Service
    http://www.synergyonline.com/blog/blog-moss/Lists/Posts/Post.aspx?ID=17

    In a class I teach, I develop a web part that use the AutoCompleteExtender to return a list of matching contact names.  Here is the web service portion of that example, so you can see the syntax I used.  Your logic, of course, will be different.

    I can send you the client part, but this will be different that what you're doing since mine was based on a web part.  Incidentally, I do have a script manager on the page (it is required), but I do not use the EnablePageMethods attribute and it works just fine.

    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    [ScriptService]
    public class AJAXDemos : System.Web.Services.WebService
    {
        [WebMethod]
        public string[] GetContacts(string prefixText, int count)
        {
            //Get our current web context
            SPWeb web = SPContext.GetContext(HttpContext.Current).Web;
            int rowCount = count;
    
            //Reference the Contacts list
            SPList list = web.Lists["Contacts"];
    
            //Create an SPQuery to return all contacts sorted by last name
            SPQuery query = new SPQuery ();
            query.Query = "<Where><BeginsWith><FieldRef Name='Title'/><Value Type='Text'>" + prefixText + "</Value></BeginsWith></Where><OrderBy><FieldRed Name='Title'/></OrderBy>";
    
            //Execute query    
            SPListItemCollection items = list.GetItems (query);
    
            //set the count of rows appropriately
            if (items.Count < rowCount)
                rowCount = items.Count;
    
            //declare our array to hold the contact list
            string[] arrContacts = new string[rowCount];
    
            //Store our SPListItemCollection into string array
            for (int i = 0; i < rowCount; i++)
            {
                arrContacts[i] = items[i]["Last Name"].ToString();
            }
            return arrContacts;
        }
    }
    



    Randy - http://sharepointhawaii.com/randywilliams
    Tuesday, December 1, 2009 1:20 PM
  • There is a hot fix for this issue as well:

    http://support.microsoft.com/kb/957661
    Wednesday, March 10, 2010 7:29 PM
  • Hi, i tried your Webservice, but when i use some Sharepoint Classes in the service and i type a word in the textbox, it requires me to login with user credentials. When i use the following sample code the AutoCompleteExtender works fine:

    List<string> foundPosts = new List<string>();
     
            foundPosts.Add("test");
            foundPosts.Add("power");
            foundPosts.Add("blaaaaaaa");
            foundPosts.Add("Windows");
            foundPosts.Add("Linux");
     
            return foundPosts.ToArray();

     

    Whats wrong? are there any security secific issues`??

     


    Tuesday, April 12, 2011 9:47 AM