Thursday, 18 June 2009

How to import your exisiting contacts from your old Nokia phone to your new iPhone?

You may want to import your existing contacts from your old Nokia (or in general VCard format) to your new iPhone.
You need to do some simple steps:
First you need to have Outlook and iTunes installed on your computer, then copy your .vcf files to a location in your hard disk, e.g. C:\VCARDS. Now when you open .vcf files, Outlook brigs a window, then you can save and close the window, the contact file is imported to your Outlook's Contacts. You need to repeat this action for all of your .vcf files. (I'll explain a way for bulk importing contacts later in this article)
After that you import all of your contacts to Outlook, you can simply synchronize iTunes contacts with Outlook and your iPhone. Done!

But there is still one issue remaining, importing all of your .vcf files manually is a very time consuming and boring job, let's write a code to do this automatically for you!
I've taken this code from here. Nice piece of code!

Here is the steps you need to do:
This can also be done using a VBA macro. First create a folder on the root of the C: drive and name it VCARDS. Next copy all your individual vCard files (.vcf) to this newly created folder. Next open Outlook and click ALT + F11 to open the VBA editor.

Click TOOLS --> REFERENCES and then select Microsoft Scripting Runtime and Windows Script Host Object Model from the list and place checks in the box next to each and click OK.

Next click INSERT --> MODULE and copy and paste the code below into the blank module. Save and run the macro to automatically import and save all the individual files into Outlook.


Sub OpenSaveVCard()

Dim objWSHShell As IWshRuntimeLibrary.IWshShell
Dim objOL As Outlook.Application
Dim colInsp As Outlook.Inspectors
Dim strVCName As String
Dim fso As Scripting.FileSystemObject
Dim fsDir As Scripting.Folder
Dim fsFile As Scripting.File
Dim vCounter As Integer


Set fso = New Scripting.FileSystemObject
Set fsDir = fso.GetFolder("C:\VCARDS")

For Each fsFile In fsDir.Files

strVCName = "C:\VCARDS\" & fsFile.Name
Set objOL = CreateObject("Outlook.Application")
Set colInsp = objOL.Inspectors
If colInsp.Count = 0 Then
Set objWSHShell = CreateObject("WScript.Shell")
objWSHShell.Run strVCName
Set colInsp = objOL.Inspectors
If Err = 0 Then
Do Until colInsp.Count = 1
DoEvents
Loop
colInsp.Item(1).CurrentItem.Save
colInsp.Item(1).Close olDiscard
Set colInsp = Nothing
Set objOL = Nothing
Set objWSHShell = Nothing
End If
End If

Next

End Sub



Thanks Rollin for the code.

Tuesday, 9 June 2009

The request failed with HTTP status 417: Expectation failed.

When using WebServices and calling some Web Methods, you may come across to this exception:
The request failed with HTTP status 417: Expectation failed.


When Expect 100-Continue property is set to true (this is actually set within part of the .Net framework, which makes this a difficult problem to overcome. You have to override this in more than one place), this 417 error occurs when the proxy server doesn't support 100-Continue.

In the case of expect 100-Continue, the client will expect to receive a 100-Continue response from the server to indicate that the client should send the data to be posted. This mechanism allows clients to avoid sending large amounts of data over the network when the server, based on the request headers, intends to reject the request.

The Expect 100-Continue behavior is fully described in IETF RFC 2616 Section 10.1.1.

You can also read more about it in MSDN.

To workaround this exception you can do a simple thing: Disable expect 100 continue.

So you may ask how to disable expect 100 continue?

Warning: When you disable Expect 100-Continues and your application sends a large amount of data on the network, if for any reason the server rejects your request, you have to re-send the entire data again, this may cause some extra traffic in your network. Also multiple calls to a server will take longer, since each call will wait until the prior call's response is received.

It is easy, here are two alternative ways:

1) We need to have this line of code before making any web requests.

System.Net.ServicePointManager.Expect100Continue = false; 


2) Add these lines to the application's configuration file (between and ):
<configuration> and </configuration>):
<system.net>
<settings>
<servicePointManager expect100Continue="false" />
</settings>
</system.net>


While this workaround is nice, I think a better long term solution is to upgrade/replace the proxy server to handle 100-continue calls.

So far in this short tip we've learned what is Expect 100, how it is caused and how to workaround this expectation.

Wednesday, 3 June 2009

Passing parameters of char* data types from C# or VB code to a C++ function

Some times you may need to use some C++ functions in your managed C# or VB code.
According to Frank Boyne, there are three ways to do this, if you choose the third method (which is easier and better, I think), you may have some problems passing variables of char* (or other pointer types) from your C# or VB code to your C++ code (in this case the wrapper class).
Suppose that you have something like this in your C++ wrapper class:

static char* foo(char *name)


the problem is this: How can I pass the value of the parameter name and how can I use the value returned by the function.

To pass the value of parameter name, you can simply use:

(char*)Marshal.StringToBSTR("VALUE")


in your C# code.

And to get the returning value of the function, you can use this code:


string s =
new string(
CPP_Managed_DLL.Class1.foo(
(char*)Marshal.StringToBSTR("VALUE")
)
);


Thursday, 28 May 2009

Internet Explorer 8: Compatibility View

There is a new feature in Internet Explorer 8, called Compatibility View
Microsoft redesigned layout rendering engine of IE 8, some times this causes older web sites not to be correctly displayed in IE 8, which were looking good in IE 7 and earlier.
So resolve this issue, IE 8 has a feature to change the layout rendering, called "Compatibility View", by selecting this option, you tell the browser to render as if it is IE 7.

If your old web sites have some trouble displaying in IE 8, and you do not want to solve those problems, an easy way is just to say the IE to render it in IE 7 mode.

You just need to add this line of code in your head section of your HTML pages:
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />


That's all!

Monday, 25 May 2009

Windows 7 Managed Code APIs

Have you ever tried to use some Windows APIs in programming languages other than C/C++?
You had to write some wrapper classes and that was really a time consuming and some times a complicated job, and some times you may ended doing that job, canceling the entire project, or using C/C++.

Some APIs are easy to implement in other programming languages, but some are really challenging.

Here is a good news for .NET developers: Microsoft announced "Windows API Code Pack for Microsoft .NET Framework"

Simplifying the use of Taskbar, Libraries, Sensor, and multi-touch from your .NET application.

Here you can read more about this pack and you can download it from here.

Wednesday, 6 May 2009

How to Disable Cellular Data Network (Internet) on iPhone?

Before iOS 4, you could not disable cellular data network on your iPhone easily, to solve this issue in your iPhone whose OS version is less than 4, you can follow these instructions:

You may need to disable cellular data network on your iPhone in some conditions, after tapping menus and wasting your time, you may find out it is impossible, or you can not find it!

Your first choice is right, it is simply impossible!

So how you can prevent your iPhone from accessing cellular data network?

1) Tap Setting -> General -> Network -> Cellular Data Network
There you will see some boxes to enter user name, password and etc. You need to simple enter some wrong data! Then turn your phone off and power it on again.
That's all!
And if you would like to use cellular data network again, you just need to roll back the settings you made.

2) Simply ask your operator to disable cellular data network for your sim-card!

3) Upgrade your iPhone OS to iOS 4 and follow the following steps.


After iOS 4, you can switch on or off cellular data network easily using:
Setting -> General -> Network -> Cellular Data

Tuesday, 7 April 2009

How to Increase VMWare Hard Disk Size?

I've been playing with virtual machines and testing some odd things that can not be easily tested on a real computer, suddenly I come across to a situation that my virtual machine's hard disk size needed to be increased.

It is one simple command! You just need to go where you installed VMWare WorkStation, there is a file named: vmware-vdiskmanager.exe

You just need to open a command window and run:

vmware-vdiskmanager.exe -x sizeGB virtualDiskFile.vmdk

That's all.