Silverlight 2.0: OpenFileDialog, et. al.

Silverlight 2.0 enables developers to open and read local files outside the Isolated Storage. I’ve tried out the examples available on the internet but most examples are made with the pre-Release To Web (RTW) version of Silverlight 2.0 and I made some examples on how to use this feature with the RTW version.

Typically, prompting the OpenFileDialog is triggered with a button click and the code snippet that you will be seeing below is a typical OpenFileDialog scenario in a Silverlight 2.0 application.


private void Button_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog ofdSample = new OpenFileDialog();
ofdSample.Multiselect = true;

// You can specify the file filters that you want to use.
// For example, if you want to additional files to filter
// you may use the following:
// ofdSample.Filter = "Text files (*.txt;*.xml)|*.txt;*.xml";

ofdSample.Filter = "Text Files (*.txt)|*.txt";

// The example: if (ofdSample.ShowDialog() == DialogResult.OK)
// won't work with RTW version of Silverlight 2.0

if (ofdSample.ShowDialog() == true)
{
// Suppose we enabled multi-file select (see line #4 of this snippet),
// we can get the total number of files by doing the following:

int ofdNumSelectedFiles;
ofdNumSelectedFiles = ofdSample.Files.Count(fi => fi.Name.Trim() != "");

// If in case you want to loop through the various files selected,
// a cast is needed to get the FileInfo properties of each file selected.

FileInfo[] ofdFiles;
ofdFiles = (FileInfo[])ofdSample.Files;

// An example of looping through the files.
for (int fileCounter = 0; fileCounter < ofdNumSelectedFiles; fileCounter++)
{
MessageBox.Show(ofdFiles[fileCounter].Name);
}

// Just in case you want to validate the number of
// files selected IF MultiSelect is set to true
MessageBox.Show(ofdNumSelectedFiles.ToString());

// Sometimes, we want to load text files into Silverlight
// controls such as a TextBox. Suppose I have a Silverlight
// control named "txtDescription" and I want to load the
// contents of the text file into the control, I will be
// using the following lines.

// Notice that I placed it inside a try-catch block. This
// is to ensure that there are no other processes that uses
// the file.

try
{
using (StreamReader reader = ofdSample.File.OpenText())
{
txtDescription.Text = reader.ReadToEnd();
}
}
catch (Exception ex)
{
MessageBox.Show("File is inaccessible. Error returned was: " + ex.Message, "File Access Error", MessageBoxButton.OK);
}
}
}

If you would notice on line #33, I used the “Name” property of the FileInfo class. In this part of the code, you can do manipulations such as storing the file in the database (as most implementations, we just store the filename in the database while the actual file might reside in an IsolatedStorage or somewhere in the web application where the Silverlight application is hosted).  If you are a bit lost, Visual Studio provides intellisense with the properties and methods that you want to use:

intellisense

Hope this helps! Happy Coding!

NAIA Terminal 3 Impressions

I went on a week-long vacation in the home province of my father where I had the chance of experiencing first-hand the newly opened airport in Manila dubbed as NAIA Terminal 3 or “T3” for short. Marred by a lot of legal controversies and issues they have finally opened last July and with Cebu Pacific starting last August 1.

Fortunately, our flight was late August and that means that we’re getting T3 as airport. Aside from the large facility, non-passengers can get in the airport only up before to the check-in area. There’s some sort of small area for well-wishing prior departure of passengers. In the old domestic terminal, you have to check-in only in the counter where your destination is indicated (e.g. if you are going to Palawan, you can check-in only in the counter stated as Palawan or Puerto Princesa). In T3, as long as you are flying Cebu Pacific, you can check-in in any counter and there you go. We were Mindanao bound but we checked-in in the Puerto Princesa counter.

Terminal fee stays the same, 200 bucks though I would say that the 200 is better felt here than in the old domestic airport. After paying the terminal fee, we went off to our pre-departure area. It is a looong walk although there’s some sort of walkator in the area. The view from the area shows the departing/arriving passengers. One good thing to notice is the terminal is cold (well it should be as it is new) though the place is so dull. When we are about to board the plane, I am quite excited trying the tube (the “bridge” that connects the terminal to the plane) but was quite disappointed since you have to go down the tarmac and climb the stairs to the plane – quite primitive but it’s okay.

On our return flight to Manila, the way to go from the plane to the terminal is still the same though we exited on another door for the arrival area. Good thing there’s a comfort room (I suppose) on each exit gate so you can satisfy nature’s calling. It was a long walk from the gate from where we exited to the carousel getting our checked-in baggages. As I would say, the place resembles Changi Airport Terminal 2 when I went there last 2006. The form of the immigration counters are the same and even the escalator downwards going to the claiming of baggages. The lobby is large again upon exit and it is definitely bigger than Terminal 2.

Of course, things are better appreciated through pictures. You can view them here.

POSTSCRIPT: I just noticed in our airport of departure for Manila that starting 2 September 2008, Cebu Pacific’s free baggage allowance would be 15kgs down from 20kgs. Bad news for backpackers. 😦

Saving For Something

Just some tips on how to save money for something – emergency, impulse buying etc.

Whenever I have loose 10 peso coins, I always see to it that that would be saved somewhere. I am in a way “inspired” by my officemate who first started collecting 10 peso coins as well and I have decided to follow suit.

What I usually do for every payday, after paying the bills that I am obligated by my parents to pay, I keep a certain amount to be used for my daily expenses. 200 pesos would be enough for a day that would include fare, food, and other miscellaneous expenses that may come in the day. Should I exceed 200 pesos, the excess amount would be deducted from my 200 pesos allowance for the next day. If I spent less than 200 pesos a day, the remaining amount or any 10 peso coin for my personal consumption would go to my ped (as seen above). Since the 200 pesos is the daily “allowance”, anything I can save is considered as “expenses” even if I save something.

The coins in return are grouped into pieces of 10 (except for the 1 peso coins which I group in 20s) for proper handling and accounting. Once my ped is filled-up with coins, I put them in a coin bank or deposit it and that in turn appears to be an “additional” income for myself. I remember during my planning for payment of my last lens purchase, I told myself that I want to keep my monthly dues below 3,000 pesos. On the day that I was suppose to buy the lens, I remembered that I have 10 peso coins in my ped that I can use for my purchase. If you’re going to fill up the right most part of coins with groups of 10 peso coins, it can fill-up up to 27 pieces thus giving me an extra of 2,700. That instantly reduced the monthly amortization that I have to pay for the lens.

Living in a complex behind a flagship branch of a popular mall here in the Philippines makes me vulnerable to impulse buying. Sometimes the budget allotted for something goes to the item I want to buy for the sake of just buying it. With this practice, it would be easier for me to acquire something for less as I don’t totally spend the whole amount of the item I want from my main sources.

Hope this one gave you an idea as well on how to save for something.

Hong Kong Tips?

Uh, ok. I took the bait. I am flying to Hongkong. I originally intend to go Vietnam for a possible photo shoot (and I think they have better tourist spots than HK) but going there alone might not be a good idea. My first travel outside the country was a bit “safer” as someone would welcome me from the airport and fortunately stayed in their place saving me money should I book a hostel. Hongkong would be a good destination for me since as a photography enthusiast, I can buy cheaper gears there than here in the Philippines and maybe I can complete the filters line-up that I am eyeing. Not only that, I can do a side-trip to Macau, if possible. And of course, I am not travelling alone.

However, my flight is still months away but at the least I am quite secured with the ticket – that’s the one that is so difficult to acquire so I’d rather book it as early as possible. Although I am quite fortunate that I still have enough time to scout for an accommodation in HK. If anyone of you have some answers to my questions, feel free to comment below:

1. Where would be the best place to stay? The choices for the hostel that we are looking at are the following: Causeway Bay, Hong Kong, Kowloon, Mongkok, Tsim Sha Tsui.

2. Cheapest yet acceptable place to stay in the answer in #1. I am not sure if true but according to some readings over the internet, Tsim Sha Tsui is the nearest accommodation location for shops of photography gears.

3. We might do a side-trip to Macau, another thing to consider your answer to #1.

4. Suggested itinerary to make the lowest expenses yet enjoyable experience in Hongkong?

5. Approximate budget of 300 USD for 5 days stay excluding shopping.

I hope I do not sound demanding. Either way, I am just a poor guy who wants to travel. 🙂

I’m Back

img_1051.jpg

I’m already done with my heartache leave (ampf). Been somewhere up north to have some relaxation and some photos. The weather wasn’t that good – been cloudy 80% of the time but it barely rained hard (even if there are no stars at night). I’m currently sorting out my photos and will group them on a per day basis.

Moreover, I’m also finalizing my day to day journal and perhaps some tips to consider when going up there.  My heart is already quite OK, the bandage can now be removed but still with small wounds to heal. LOL!

Beware of the ATM Modus Operandi

My officemate sent a link to our group about a recent modus operandi (aka scam) that victimizes ATM clients. Curious?

b1.jpg

 We may already have heard about this scam many times before, but sometimes we forget and need to be reminded, especially this coming Christmas season.

I was withdrawing last Saturday, Nov 17 10pm at a Bank of Commerce ATM near McDonald’s corner Pasong Tamo and Gil Puyat in Makati. There seemed nothing wrong  with the ATM but no cash came out of the machine. I automatically thought it was just a machine error and that my account was debited because when I checked my balance, it was deducted by the amount I was supposed to withdraw.

But since I wanted to be sure and I needed cash, I waited for a few more seconds and carefully checked where the cash should come out. I noticed a light blue  steel bar where the cash dispenser should be and looked underneath it. There was no outlet where the cash should come out. Suddenly remembering the ATM scams I’ve heard about, and now feeling sure that that bar shouldn’t be there, I took a photo of it then tried removing it from the machine. It had to take a  lot of effort but when I finally got the bar off, I was surprised to see my money caught in the bar with black glue (probably put inside the bar to keep the  cash from going back to the machine). See attached photo.

So please, please carefully check the ATMs you use and as much as possible withdraw only during daytime, or on guarded ATMs to avoid being scammed. Please forward this to as many people as possible to warn them.

This holiday season, due to the hardships of life, some people resort to cheat and deceit just to earn money. May this post serve as a warning and I hope none of you gets victimized by this group.

ASP.NET Membership Schema

I was googling for the ASP.NET Membership Database Schema (the ASPNETDB.mdf in App_Data folder) for some small project but I can’t seem to find one. The following keywords were used “asp.net membership diagram”, “asp.net membership database diagram”, “asp.net membership schema” but none of them gave me relevant results.

As a result, I instead create a diagram of my own that can be printed clear on a letter (8.5×11) paper. You can download it here.