Search.aspx.cs Modification to allow ...

Feb 14, 2010 at 1:34 AM
Edited Feb 14, 2010 at 2:12 AM

Well, migrating from blogger to BE.NET is quite a pain specially in re-tagging the posts plus I have 4 blogs.

Another pain killing action will be redirecting blog posts from blogger to BE.NET blog post. But how do we do this?

So far I only managed to do it using Search. Sorry.

Anyway, I have written a small method called:
BloggerReTerm(string q)
Get the filename in the url and convert those dashes into spaces. If it didn't find any, it will redirect you to your home domain.

 

string BloggerReTerm(string q)
{
	string ret = string.Empty;

	string[] a_q = q.Split(new char[] { '|' });

	// make sure the query came from blogger
	if (a_q[0].ToLower() == "blogger")
	{
		// get the file
		string page = System.IO.Path.GetFileNameWithoutExtension(a_q[1]);
		//string page = a_q[1].Substring(a_q[1].LastIndexOf('/') + 1);
		// and leave the type
		//page = page.Substring(0, page.LastIndexOf('.'));

		// remove the dashes and replace it to spaces
		ret = page.Replace("-", " ").Trim();

		if (ret != string.Empty)
		{
			ret = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(ret);
		}
		else
		{
			HttpContext.Current.Response.Redirect("http://" + HttpContext.Current.Request.Url.Host.ToString());
		}
	}
	else
	{
		ret = q;
	}

	return ret;
}

add that method in Search.aspx.cs

and of course .. some modifications are need in Search.aspx.cs

+ line 18: string term = string.Empty;
= line 35: term = Request.QueryString["q"];
+ line 36: term = BloggerReTerm(term); 
= line 37: Page.Title = Server.HtmlEncode(Resources.labels.searchResultsFor) + " '" + Server.HtmlEncode(term) + "'";
= line 38: h1Headline.InnerHtml = Resources.labels.searchResultsFor + " '" + Server.HtmlEncode(term) + "'";
= line 110: Page.Title = "APML matches for '" + term + "'";

How this modification will work?

Go to your blogger layout page and add new HTML/Javascript element.

and add this line. for example mine.

 

<script type="text/javascript">
window.location = "http://www.jaysonragasa.net/search.aspx?q=blogger|" + window.location.href;
</script>

If you want to test it out.

try this link: http://jaywinmodev.blogspot.com/2010/02/ubuntu-os-running-on-xperia-x1.html

and for labels: http://heresmycode.blogspot.com/search/label/C#

Am not trying to make a miracle here but if you found this helpful. Then Thank you!