using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Text.RegularExpressions; namespace Search4SharePoint { public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { String query = Request.QueryString["q"]; if (!String.IsNullOrEmpty(query)) { q.Text = SanitizeUserInput(HttpUtility.UrlDecode(query.Trim())); } } } /// /// Using the Google form field values, redirect to this page with those values in the URL's /// query string. Google's JavaScript will pick up these parameters, perform the search, and /// display the results on your page. /// /// /// protected void _btnSearch_Click(Object sender, EventArgs e) { if (!IsValid) return; Response.Redirect( String.Format( "Default.aspx?q={0}&cx={1}&cof={2}", HttpUtility.UrlEncode(SanitizeUserInput(q.Text.Trim())), HttpUtility.UrlEncode(cx.Value), HttpUtility.UrlEncode(cof.Value) ), false ); Context.ApplicationInstance.CompleteRequest(); } /// /// Strip tags from user input. /// /// /// private String SanitizeUserInput(String text) { if (String.IsNullOrEmpty(text)) return String.Empty; String rxPattern = "<(?>\"[^\"]*\"|'[^']*'|[^'\">])*>"; Regex rx = new Regex(rxPattern); String output = rx.Replace(text, String.Empty); return output; } } }