Blog of a Filipino Developer about C#, VB.NET, ASP.NET, Java, PHP, SQL Server, MySql and Oracle RSS 2.0
 Monday, November 19, 2007

"Ayayay Caramba!" Another great app from the makers of VisualSVN.

Introducing VisualSVN Server. VisualSVN Server is a packaged that contains all you need to start(and managed) your own SVN repository. Think of it as your own mini toolbox of goodies for SVN. The package comes with SubVersion, Apache and sleak lookin' management console.

And best of all, it's 100% free.

Monday, November 19, 2007 10:02:05 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
Tech News and Issues

Oh boy! Oh boy! Oh boy! Talk about geeky goodness! In case you miss the news, VS 2008 is ready for download for MSDN subscribers. Not an MSDN subscriber? Fear not! VS Express 2008 was also shipped today!

Want to learn whats on VS2008? Check out the video tutorials here or just read what ScottGu has to say.

Jeff also mentioned that Team Suite and TFS is also available and that the 90 day trial(in case you are not an MSDN subsriber) can be downloaded from the MSDN website.

Monday, November 19, 2007 8:19:50 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
.NET | Tech News and Issues
 Saturday, November 17, 2007

More than 2 years ago I wrote this article and submitted it in CodeProject detailing how you can build a FileSystem Browser in ASP.NET. The article talks about how newbie ASP developers moving to ASP.NET might code the solution and how somebody a little bit more familiar with ASP.NET would build the same application in lesser code.

Somebody emailed me about my article yesterday asking for some guidance. This lead me to inspect my old article. The first thing i said to myself after seeing my old code is 'Yikes! I did that?'. Yup, it was that horrible. The solution works, its functional based on the need but I knew i could clean it up and code it much better if i had the chance to do it a second time around. That chance happened today.

I haved changed the way i read folders(before it was using query strings). I have replaced that logic by placing the path inside my LinkButton CommandArgument property. How i pass the FileSystemInfo[] to the grid(it was using an intermediate datatable) and the type of control that displays the data(it was using a datagrid before now we are using a gridview). I've also added a breadcrumb like control to track the users location and made it a little bit prettier by adding icons instead of plain text descriptions.

I'll be updating this constantly based on the request I haved received from my original article. The most common request is sorting which I will add on the next release.

Hopefully this version is less crappier than the last.

*Update*

Thanks to Andreas Haydeck for pointing out a bug in the BuildNavigatorPath method that causes the navigator path not to show the proper folder location. This has been fixed and the code in this article has been updated.

Download the latest source here: KeithRull.FileSystemManagerRevisited.zip (6.57 KB)

Saturday, November 17, 2007 12:02:24 AM (GMT Standard Time, UTC+00:00)  #    Comments [5] -
.NET | Fun Stuff
 Wednesday, November 14, 2007

I was explaining the benefits of outsourcing projects in Manila today to someone who has a huge project.. probably between 1 year to 2 years of development amounting to atleast $50K for the initial concept. He asked me to help him find a suitable outsourcing company preferrably in Asia. I then made a push to have him look at several company's in Manila which he agreed... what i did next was show him a website of a known development company. He read everything and browsed every page on their site to get more information about them. We were having a great conversation and I think he ha already decided that he is going to contact this one company but then he decided to look at their methodologies section... there he noticed something that he didn't like about the website...

"Some comment?" What? Nice coding standard there buddy.

I mean, come on! If you are posting a code snippet to an ad atleast make sure that the code looks good and follows your motto "Code of Discipline" because to tell you frankly it makes your company look bad when you don't QA what you push to visitors even if it's just an image.

In the end, he got turned off and asked me to show him a different outsourcing company.

Sad. Sad. Sad. A missed opportunity.

Wednesday, November 14, 2007 1:12:03 AM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
All about Keith | Tech News and Issues | Your Career
 Tuesday, November 13, 2007

Man, this is fast becoming an all out war. I think Mr. Gates and Mr. Jobs would be anxious on whats going to happen with this latest release from Google specially knowing that Google is giving away $10,000,000 to the best application built on top of the Android platform

Check out the video here:


 



 



 



 



 


 

Tuesday, November 13, 2007 9:58:43 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
Tech News and Issues
 Friday, November 09, 2007
"Nobody should tell you what you want to be in life. Stick with your dream and don't let anybody tell you that you can't make that dream happen."
 
I was browsing technorati today when I stumbled upon this blog entry from an aspiring developer in Manila. My heart shrunk after reading her dilemma.
 
"...I told my family that I want to be a Software Developer that's why I keep on reading and studying about new programming technologies. But my family objects, especially my mom. They don't want me to study. They just want me to pick  whatever job and stick to it. One day, they even kept my programming books in a locked shelf. Imagine, they don't want me to be a programmer..."
 
I had the same situation more than 3 years ago when i got here in the US. You see, I was a developer in Manila before my family decided to move to the US for a big outsourcing company doing VB6, VB.NET, C# and ASP. I was a Web Administrator for a real state firm before that(doing classic ASP and PHP) and a Analyst Programmer Trainee when I was in college. But almost everybody in my dads side of the family thinks that i should be a US Navy. They said that i can't find any developer job here in the US because "I graduated in the Philippines" and that i can't use my degree because the school that i can from has a curriculum that isn't recognized by the academe in America.
 
My heart was broken after hearing that from several people... it's hard to accept that what you have worked hard on for 4 long years wont amount to anything in another country. Alot of people told me to give up my dream and just "settle for what's on the table" which means that i just need to take what i can and not live up for my aspirations.
 
Hearing those kind of opinion specially coming from your family members is somewhat dishearthening.
 
At first, I was discouraged. I wasn't mad at them at all but i didn't believe what they told me. I knew that I can accomplish my dream if i work and pray hard for it. I worked doubly hard going to the library to read a book everytime I can. I would even borrow books and rigorously read them till i fall asleep. I didn't had the chance to bring my development tools at that time because i was advised not to bring my CDs so i ended up downloading everything all over again via a 56kbps line. I was lucky enough to find SharpDevelop and that's how i started honing my skills in C#(and VB.NET). Everyday I gain more and more confidence in myself knowing that every tear and pain is a step towards my goal to become a Software Developer in the US.
 
My first job interview was a disaster. I was sweating like a sheep and so nervous that i dabbled every word I spoke. I knew all the questions they asked me but i wasn't able to communicate well enough to merit me as a valid candidate for the position. I knew right there and then that I failed the job interview. I was sad but held my head up high knowing that I needed that stab so I can be better.
 
I became event more confident after that faithful event. Taking every piece of experience i learned from it as part of my comunication toolbox(and that is speak clearly, be yourself and don't sweat like you don't know what you are talking about).
 
I prayed harder too knowing that God has something prepared for me in my future and I was right!
 
After a month of applying and staying long hours sending my resume our home phone rang with someone on the other line bringing me a message... I was hired and they wanted me to start that week. After putting the phone down i started shouting like crazy. It was so sweet to let that out of my chest that finally, my dream is coming true.
 
It's been more than 3 years ago since that faithful day. I smile everytime I think of what I have accomplished even with almost everybody saying that I can't be who I want to be. I knew God has promise for me and that it would happen if i work hard and continue to believe Him.
 
And it did :)
 
I believe that nobody should tell you to stop dreaming. I believe that you can accomplish anything you want as long as you put your mind, body, heart and faith into it. Anything is possible as long as you work hard, believe and put your trust in God.
 
Through that battle I held a verse in my heart which I'd like to share to you:
"Have I not commanded you? Be strong and courageous. Do not be terrified; do not be discouraged, for the LORD your God will be with you wherever you go."
                                                   Joshua 1:9 - taken from the NIV Bible
 
So I say to you all "Dream on, don't loose hope and never let go!".
Friday, November 09, 2007 7:08:45 PM (GMT Standard Time, UTC+00:00)  #    Comments [2] -
All about Keith | My Faith | Your Career

James McGovern has has posted this stat on how vast the network is inside the Big House in Redmond and i'm quite amazed in their IT infrastructure:

Microsoft internal IT:

600k connected devices
10,000 Servers
3 Datacenters 1 operations center
11% is virtualized in Microsoft Datacenters
330 of 385 servers run Windows Server 2008 (RC0) plus all 85 Microsoft.com servers
11 clustered systems
30,000 users in redmond domain (50,000 with vendors)
NAP reporting 140K clients, 90 clients deferred mode

The Redmond Active Directory domain is running in Windows Server 2008 mode since last thursday (Nov 1st)

Microsoft Email:

6 million internal emails per day
20 Million emails from Internet
97% rejected as spam
99,999 uptime

Want to read more? Go to James McGovern's website and check out this crazy stat.

Hmmm... I wonder how many geeks are running the show in such a huge network. Hmm.. Do you know?

Friday, November 09, 2007 12:12:11 AM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
Tech News and Issues
 Thursday, November 08, 2007

I know, i missed alot after i didn't go to MIX07. I told Jon that i'll be coming to MIX07 but something happened with my project and i was asked to tend the wounds. This time I won't let the chance to party with Miguel, Jeff, Phil and Scott pass me by!

MIX08 here I come!

Thursday, November 08, 2007 9:40:22 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
Tech News and Issues
 Wednesday, November 07, 2007

My friend Mohammad Azam (Azamsharp) of GridViewGuy.com is looking for talented developers who also have extra-ordinary writing skills. He is looking for people who can contribute well-written articles to his website and in return he'll pay you $10/per article. So if you think you are up for the challenge and you have the skills and the motivation to write then send him a message at azamsharp@gmail.com.

Wednesday, November 07, 2007 8:34:49 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
.NET | Fun Stuff | Tech News and Issues

Yesterday I wrote a post as about adding a mailto link to a GridViewColumn and was surprised with the amount of response i got via email regarding that topic. One person asked me a frequently asked question which i realized I haven't tackled on my blog yet. The question was:

Keith,

   Is it possible to add javascript code in a GridView Column? I'd like to attach a javascript function to a hyperlink that will show an alert that show's the selected Name whenever a user clicks that link.

Thanks,

XXXXX (Identity hidden)

The answer to the question is Yes you can add javascript code to a control inside your GridView and believe it or not there is two ways to do it. There's the easy way and there's the complicated but not hard to do way.

Let's start with the easy way. The easiest way to do this is by create a TemplateField in your GridView and add a HyperLink control inside the ItemTemplate of your TemplateField. Next, you need to modify the NavigateUrl property of the HyperLink control to something similar to this:

<asp:TemplateField>
   <ItemTemplate>
      <asp:HyperLink ID="selectionHyperLink" 
                     runat="server" 
                     NavigateUrl='<%# Eval("Name", "javascript:showMessage(&#039;{0}&#039;);") %>'
                     Text="Select" />
   </ItemTemplate>
</asp:TemplateField>

What the code on my NavigateUrl property does is that it attaches a javascript function called showMessage passing a parameter which in this case is a value from column taken from the binded datasource of the GridView. The javascript for the above code would like this:

<script language="javascript">
   function showMessage(personName)
   {
      alert("You clicked " + personName + "!");
   }
</script>

The second approach is adding a GridView_RowDataBound event to our GridView and add some control logic inside that event but first we need to modify our control attributes:

<asp:TemplateField>
   <ItemTemplate>
      <asp:HyperLink ID="selectionByCodeHyperLink" 
                     runat="server" 
                     Text="Select" />
   </ItemTemplate>
</asp:TemplateField>

As you can see i have removed the NavigateUrl attribute. The reason behind this is because i'll be feeding that information inside the GridViewDatabound event. To accomplish what we have accomplished on our first example we need to decide on two things: 1.) Do we want to use the same logic wherein we specify the javascript via the navigate url? or 2.) Do want to use the Control.Attribute.Add() method of the control to attach a onclick event to it.

Anyway, I'll leave that thinking to you and just show the code for both instead so that you can choose which approach is right for you:

Here's the code for the straight up NavigateUrl assignment of the javascript.

protected void peopleGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
   //determine if the row type is DataRow
   if (e.Row.RowType == DataControlRowType.DataRow)
   {
      //find the hyperlink control in the GridView
      HyperLink hyperLink = (HyperLink)e.Row.FindControl("selectionByCodeHyperLink");

      //check whether the the hyperlink exist on our GridView
      if (hyperLink != null)
      {
         //get the dataitem assigned to the row.
         //assume that the dataitem is of type Person
         Person person = (Person)e.Row.DataItem;

         //assign our javascript code
         hyperLink.NavigateUrl = String.Format("javascript:showMessage('{0}');", person.Name);
      }
   }
}

As you can see, all we did was assign the same string that we assigned on our first example. Below is the add attribute version of the above code.

protected void peopleGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
   //determine if the row type is DataRow
   if (e.Row.RowType == DataControlRowType.DataRow)
   {
      //find the hyperlink control in the GridView
      HyperLink hyperLink = (HyperLink)e.Row.FindControl("selectionByCodeHyperLink");

      //check whether the the hyperlink exist on our GridView
      if (hyperLink != null)
      {
         //get the dataitem assigned to the row.
         //assume that the dataitem is of type Person
         Person person = (Person)e.Row.DataItem;

         //add this code to make the text act as hyperlink
         hyperLink.NavigateUrl = "javascript:;";
         //add our javascript attribute
         hyperLink.Attributes.Add("onclick",String.Format("javascript:showMessage('{0}');", person.Name));
      }
   }
}

And that's it! That's how you add javascript code to controls inside a GridView. Hope that you learned something from this tutorial. 

Want to download the source for this project? Get it here: KeithRull.MappingLinksInGridViews.zip (3.28 KB)

Wednesday, November 07, 2007 7:41:23 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
.NET

I was reading my site refferers today when I saw an interesting refferer query that came from Google. Three people got to my site after typing this phrase "hyperlink databind gridview mailto". I went to the the Google results page and immediately went to the page the was indexed by Google and upon futher review i found that my page wasn't really the answer to those persons question. Out of my curiousity i fired Visual Studio 2005 up and tried to add mailto link to a GridView using the HyperlinkField as my base.

<asp:HyperLinkField  DataNavigateUrlFields="Email" 
                     DataNavigateUrlFormatString="mailto:{0}"
                     DataTextField="Email" Text="Email me!" />

I ran the project thinking that this should work because this always works for me when i do same process for URLs. To my surprise, it didn't. For some unknown reason the column appears as plain text without any href attribute in sight. I went back to the HTML and checked it twice to see if maybe i missed something on the control attributes... hmmm, eveything looks ok. After a few minutes of playing around I resorted to the technique that never fails.. I converted the column to a TemplateField.

<asp:TemplateField HeaderText="Email">
   <ItemTemplate>
      <asp:HyperLink ID="emailHyperLink" 
                     runat="server" 
                     NavigateUrl='<%# Eval("Email", "mailto:{0}") %>'
                     Text='<%# Eval("Email") %>' />
   </ItemTemplate>
</asp:TemplateField>

Run the project again and sure enough, it worked. Huh! Weird! Anybody who knows what happened?

Wednesday, November 07, 2007 12:02:15 AM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
.NET
 Tuesday, November 06, 2007

A fried of mine IM'ed me today asking for help about an specific task that was assigned to him by his project manager. He is currently working on a project that has the client getting furious alot because the client discovered that most of the links on their site were broken (the vicious 404 erros) or are not pointing to the right pages (misplaced links). His PM wasn't happy at all so he was asked me to help him create a program that would parse a website and get all URLs accessible inside a page and dump the result into a text file.

I had a little bit of free time so i decided to help him by building this small application to show him how he can accomplish the task in C#.

using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.IO;
using System.Net;

namespace KeithRull.GiveMeUrls
{
   class Program
   {
      static void Main(string[] args)
      {
         //the url to scrape
         Uri urlToScrape = new Uri("http://www.devpinoy.org");
         //the list that would contain the urls recovered from the specified uri
         List<string> listOfUrls = GetAllUrlsFromUri(urlToScrape);

         string fileName = SaveToFile(listOfUrls);

         Console.WriteLine("Parsing completed! Urls saved to file: {0}", fileName);

         Console.ReadLine();
      }

      public static List<string> GetAllUrlsFromUri(Uri urlToScrape)
      {
         //the list that would hold the urls
         List<string> listOfUrls = new List<string>();
         //the search pattern that we are going to use for our regular expression
         string searchPattern = "href\\s*=\\s*(?:(?:\\\"(?<url>[^\\\"]*)\\\")|(?<url>[^\\s]* ))";

         //get the contents of the page and put it to a string
         string pageContents = GetPageContents(urlToScrape);

         //our regular expression should ignore case
         Regex regEx = new Regex(searchPattern, RegexOptions.IgnoreCase);

         //get all the maching values generated by our regular expression
         Match match = regEx.Match(pageContents);

         //loop thru all the matching strings
         while (match.Success)
         {
            //assign the match value to a temporary placeholder
            string urlFound = match.Value;

            //check to see if the url does not include the full path(e.g: default.aspx)
            if (listOfUrls.IndexOf(urlFound) < 0)
            {
               string urlToAdd = urlFound;
               if (urlFound.StartsWith("href=\"javascript:"))
               {
                  //do nothing, we need to display it as is.
               }
               else if (urlFound.StartsWith("href=\"/") || !urlFound.StartsWith("href=\"http://"))
               {
                  //add the scrape url to the beginning of our found string
                  urlToAdd = urlFound.Insert(6, urlToScrape.OriginalString);
               }
               //add the url to our list
               listOfUrls.Add(urlToAdd);
            }
            //move to the next match result
            match = match.NextMatch();
         }

         //return the list of urls that we have recovered from the site
         return listOfUrls;
      }

      /// <summary>
      /// Reads a webpage and captures it html representation into a string
      /// </summary>
      /// <param name="urlToScrape">the website you want to read</param>
      /// <returns>the html representation of the site</returns>
      private static string GetPageContents(Uri urlToScrape)
      {
         HttpWebResponse httpWebResponse = null;
         StreamReader streamReader = null;
         string pageContents = String.Empty;

         try
         {
            //create a webrequest object for the url
            WebRequest webRequest = WebRequest.Create(urlToScrape);
            //convert the webrequest to an httpwebrequest
            HttpWebRequest httpWebRequest = (HttpWebRequest)webRequest;
            //assign a timeout value for the process
            httpWebRequest.Timeout = 100000;

            //create a webresponse object to hold the response generated for our request
            WebResponse webResponse = httpWebRequest.GetResponse();
            //convert the webresponse to httpwebresponse
            httpWebResponse = (HttpWebResponse)webResponse;

            //get the response stream and assign it to our streamreader
            streamReader = new StreamReader(httpWebResponse.GetResponseStream());

            //read the contents of the stream
            pageContents = streamReader.ReadToEnd();
         }
         catch (Exception ex)
         {
            //buble up the error
            throw ex;
         }
         finally
         {
            //close our webresponse object
            httpWebResponse.Close();
            //close our streamreader object
            streamReader.Close();
         }

         //return the page contents
         return pageContents;
      }

      /// <summary>
      /// Saves our list of urls to a text file
      /// </summary>
      /// <param name="listOfUrls">the list containing the urls</param>
      /// <returns>the filename created for the file</returns>
      public static string SaveToFile(List<string> listOfUrls)
      {
         //the file name
         string fileName = String.Format("{0}.{1}",Guid.NewGuid(), "txt");

         //create a streamwriter for our file
         StreamWriter sw = File.CreateText(fileName);

         //loop thru each string in our collection
         foreach (string url in listOfUrls)
         {
            //write the string to our file
            sw.WriteLine(url);
         }

         //close oour streamwriter
         sw.Close();

         //return our filename
         return fileName;
      }
   }
}

Basically, the code does is it accepts a url and then parses that page using a regular expression to check all the strings that matches our search pattern. Once it finishes the processing of the page, it would then dump all those urls into a text file.

I sent the code to him and he was very happy with the result. Sweet!

Tuesday, November 06, 2007 8:21:58 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
.NET | Fun Stuff
Archive
<November 2007>
SunMonTueWedThuFriSat
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2008
Keith Rull
Sign In
Statistics
Total Posts: 246
This Year: 43
This Month: 4
This Week: 0
Comments: 111
Themes
Pick a theme:
Ads
All Content © 2008, Keith Rull
DasBlog theme 'Business' created by Christoph De Baene (delarou)