Tuesday, June 06, 2017

File upload and unzipping files

If you want to unzip a file here are few lines that unzips a zip file and delivers the contents as a stream. Here I am assuming the zip file contain images

 if (fuPhotos.FileName.ToLower().EndsWith(".zip"))
                    var za = new System.IO.Compression.ZipArchive(fuPhotos.PostedFile.InputStream);
                    foreach (var entry in za.Entries)
                        var img = System.Drawing.Image.FromStream(entry.Open());
                        img.Save(@"c:\temp\" + Path.GetFileName(entry.FullName));

 if (fuPhotos.FileName.ToLower().EndsWith(".zip"))
This line allows you to check the extension so you are certain the user is uploading a zip file. the extension is one way of detecting that.

var za = new System.IO.Compression.ZipArchive(fuPhotos.PostedFile.InputStream);
This line will get the stream of that file, you need to get a stream because the stream is a generic object that you can handle with other classes like StreamReader, StreamWriter, FileStream, MemoryStream and other objects like System.Drawing.Image that can get you an image from a stream

 foreach (var entry in za.Entries)
This line allows you to loop to work on every entry in the zip file. the entry is a file inside the zip file. you can access its name, contents, etc..

var img = System.Drawing.Image.FromStream(entry.Open());
The Image class can read a stream and entry.Open gets the stream of the entry

img.Save(@"c:\temp\" + Path.GetFileName(entry.FullName));
This line allows you to save the stream

You can deal with multiple files if the user uploads multiple files if you change your code as follows

foreach (var onezipFile in fuPhotos.PostedFiles)

                    if (onezipFile.FileName.ToLower().EndsWith(".zip"))
                        var za = new System.IO.Compression.ZipArchive(onezipFile.InputStream);
                        foreach (var entry in za.Entries)
                            var img = System.Drawing.Image.FromStream(entry.Open());
                            img.Save(@"c:\temp\" + Path.GetFileName(entry.FullName));


Thursday, January 26, 2017

How to deliver your baby in Canada for Free (Almost)

If you do not have health insurance when you first arrive to Canada and you are pregnant it will be very expensive to deliver your baby without insurance. Normal delivery is $3,000 and C-Section can reach $10,000 for more information you can review this report.

There is a free service that you can benefit from called Community Midwifes which can help you deliver for $600 including all lab work and hospital fees.

To start you need to visit Access Point on Jane which is a community center located at
761 Jane St. 2nd Floor, Toronto, ON M6N 4B4 on Thursdays from 4:00 to 7:00 PM 416-760-8677
They will interview you and ask if you are a landed immigrant and waiting for OHIP? They do not usually check ID or landing papers but it is better if you have them with you. Then they will transfer you to the nearest midwife clinic, one of them is located at 344 Bloor street west and is called Community Midwifes of Toronto. and their telephones are.

Then you will be able to see your midwife once every two weeks and then once every week, for all blood,  lab work and ultrasound they will give you a letter (which works as your insurance) that looks like this and this letter you can give to the lab and the lab will not charge you any thing.

Here is a list of all the labs that accept this payment letter.

For ultrasound they will give you a request that looks like this

If you need to see a doctor then you must talk to the midwife and she will transfer you to a doctor, not every doctor accept their payment letter but one who does is Dr. Susan Sheppard. Tel: 416-867-3728 located at 410 Sherbourne St., 4th Floor, Toronto, Ontario, M4X 1K2. For more info please visit 

The doctor can also send you to do some lab work and it is better if you go to the same list of labs above. The doctor may send you to a different lab, but you need to ask her to give you the request on ministry of health form.

If you are strong enough you can delivery in a birth center without Epidural, Toronto birth center is located at 525 Dundas St E, Toronto, ON M5A 2B6 and you can call to request a tour (416) 366-8080.

The final step is actual delivery. If you are going to delivery in the birth center then it is totally free and you do not need to pay anything. If you prefer to have an easier delivery using Epidural then you need to deliver at the hospital once of the hospitals affiliated with midwifes is St. Michael hospital which is located at 30 Bond St., Toronto, Ontario M5B 1W8.

The hospital requires a payment of $600 which covers 3 days at $200/day. your midwife will give you an admission letter and another letter like this that you need to take to the hospital and pay $600 which is a great deal.

With this payment, you will not pay any thing else for any lab work or medicine at the hospital. Even Epidural is covered in these $600.

Finally, they will give you a paper to keep in case of emergency and in case you had to go to any other hospital. These two papers contain all information about you and they look like this

Now, you should prepare for your C-Section appointment, Ours was by Dr. Howard Berger and you need the direct hospital number, their 15th Floor number is 416-864-5252

After birth, your baby will either feed on breast milk or formula and may suffer a little bit of Jaundice and you will be seen by a Pediatric in the hospital.

No matter what you do, do not go to 61 Queen st E, to see Dr. Cheema. This clinic is very unprofessional, our appointment was at 8:45 in the morning, we arrived at 8:25 AM and have only been seen at 10:00 AM imagine? they seem to be disrespectful of people's time. you will be disappointed that you keep your daughter undressed and ready to be seen for an hour.

I hope this information helps you have a smooth planning to this magical moment and best of luck.

Wednesday, January 30, 2013

Calling Javascript from Content Page

Is it really easy with play with JavaScript? for instance, If you have a content page within or referencing a master page. your content page has a drop down box and a text field.

You want to show or hide the text field based on the drop down box contents.

Let's say the drop down contain a list of airports for the user to choose from. only if the user chooses the value other in this drop down, you want to show the text field.

It may not be as simple as

if (dfcDropDown.Text == "Other") dfsTextBox.Visible = True; else dfsTextBox.Visible = False;

It will be little more involved than that.

First you need to write a function in Java script. This funtion you can not just put it anywhere in the aspx. you have to put it under the asp:Content tag. which might look like this

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">

Second you need to make a java script block and write your function using GetElementById. When calling getElementById, the Id of the control will be little tricker. you can not as a matter of fact put the Id of the control directly. you must use a syntax like this &lt;%=dfcDropDown.ClientID%&gt; to get the name of the control at run time. Here is a sample Javascript method that will hide the text box based on the drop down box value

<script type="text/javascript">
           function ShowHideTextBox() {
           if (document.getElementById('<%=dfcDropDownBoxt.ClientID%>').value == "Other")
               document.getElementById('<%=dfsTextBox.ClientID%>').style.display = 'none'; //hide textbox
               document.getElementById('<%=dfsTextBox.ClientID%>').style.display = 'block'; //show textbox

Now, we have a code that will do what we need and we need to trigger this code when the use changes the value of the drop down box. well, we can not hook this code directly to the drop down box from within the aspx. we have to use the code behind to do that. it turns out that the onChange event is not available from within the aspx page. We must hook the onChange event using c# like this

 dfcdropDown.Attributes.Add("onChange", "ShowHideTextBox();");

and we must do this in the code behind.

Not that simple haaa;

Wednesday, March 14, 2012

Reactive Extensions Gems

As I am learning about reactive extensions I want to post some code that I think is useful. Before using the code here you may want to download Reactive Extensions for your .Net Framework version. It is located at http://www.microsoft.com/download/en/details.aspx?id=24940

What it does: it will call a method called DoSomething that acceptes one parameter of type long.
What can you do with it: You can use this line to call the DoSomething every second and send emails for example. before this line you can retrieve the list of customers to send emails to, and every second grab one customer and send email to him/her

What it does: Call a method every second after waiting for three seconds initially.
What you can do with it: You can send emails to customers after waiting a specific perdiod of time.

Wednesday, February 08, 2012

Silverlight Gems


System.Windows.Browser.HtmlPage.Window.Navigate(new Uri("http://cnn.com")); //You can use "_blank" as a second paramter to popup the cnn.com in a new window


Monday, February 28, 2011

Tips for Pilgrimage to Mecca

I already wrote my experience in the Hajj of 2010 which was in Arabic and can be found here, I still have some more tricks and tips that can make your trip a lot easier. Those tricks has to do with making phone calls, transportation etc...

You should take with you

1- Odorless Soap, so you can wash after going to the toilet. You will not have time for shopping and may not find what you need.

2- Hair cutter, when you need to cut your hair you will find everyone busy and expensive. Imagine millions are looking for barbershops.

3- Towel, Some of the temporary hotels you will stay in will not provide towels. Also in the tents you are on your own.

4- Container for Zamzam water. If you buy containers from there, you will have to walk to find a store and it will be expensive.

5- Your laptop. Usually hotels will have Wifi and you can call your family using any VOIP

6- Bring your VOIP telephone (Or Magic Jack), you can connect it to the hotel internet and call your family.

7- Bring your cell phone (some people says don't because you will lose it, I'd say bring it but don't take it outside the hotel). You can get STC SIM card for 40 Rial (Pre loaded with 50 Rial)and call 902 they will give you daily internet on you SIM card. 10 Rial for one hour or 24 Rial for the whole day. They will send you a message if you click the link on it, it will setup your tel. Make sure your tel support arabic otherwise ask them to send you the message in English.

8- More than one Ihram cloth. you will need one more and washing them is the same as buying new ones. I would say bring three total.

What to do

1- When finishing tawaf try to get out gradually. if you find yourself on the 7th round and close to Kaaba try to exit the tawaf gradually and not one time.

2- After your done with Jamarat continue walking and you will find yourself out

3- in your telephone always bookmark the important locations in the map. with your GPS you can go back. Places like your tent will be ex termly important when you get lost. bookmark the location of el 7aram so you can go back to it if you get lost.

4- Go to Tan3eem to make another Omra (you can make Omra any number of times) Tan3eem bus is two Rial each way.

5- Best times for Omra (7aram will be kinda empty) 9-10 AM , 1-3 AM, 1-3 PM

6- If you are with a group, then hold hands during tawaf. you will support each other and will not fall.

7- Be vigilant they will ask women to sit in a separate area close to prayer times. If you sit beside your wife and hoping you will pray beside each other, it may not happen. They will ask women to leave their space and go somewhere else. If you are looking for a place for prayer and you see some women sitting there you can wait and take their place when they ask them to leave.

8- In Medina, best times to pray in Rawda 1:30 AM. stand b Seddek Door, they will open at 2:00 AM

9- Do not take Taxi's just wave to any car, it will stop and you can negotiate the price to go anywhere.

10-If you will take the bus from Azizia to Mena, and the bus will make two trips. get in the second trip not the first. The first trip the guide may get lost, so do not go in the first trip unless you enjoy getting lost.

11- If you can have a motor cycle for the last day of Hajj or bicycle, you will be a king in transportation.

Here is a summary for Hajj days.

Day 8 Thu Hejja (Tarwiya): sleep in Menna, wakeup at 5:00 am. Fajr prayer then bus to Arafat.

Day 9 Thu Hejja (Arafa): stay in arafat untill Maghrib, then bus to Muzdalafa, sleep in Mozdalafa in sleeping bag

Day 10 Thu Hejja (El nahr or Eid): Bus to Mena, then walk (3 Km) to Jamarat, throw first Jamara and Tahallom from Ihram.

Day 11 Thu Hejja (Tashreek Awal): Throw three Jamarat.

Day 12 Thu Hejja (Tashreek Thani): Throw three Jamarat. Tawaf Wada3, Ifada, Sa3i and leave to Airport if you are Mota3agel.