Archive for October, 2011

How to deploy sync framework to windows azure/Deploy sync framework project to windows azure

October 5, 2011 1 comment

Deployment of sync framework workerrole / webrole project into azure environment

The article is going to explain that how we can deploy sync framework worker role or webrole projects created in Visual Studio into azure environment. We have created a worker role application that sync azure databases frequently. We are using Sync Framework 2.1 for sync database in the azure. Once it is completed the application, the challenge was to deploy this sync framework to azure platform. We have to include some dlls and also need to do some configuration settings to deploy project into Windows Azure platform

 Steps to do for deploying Sync Framework Project into Azure

 1.Open your Windows Azure Cloud Service project in Visual Studio >> In the Solution Explorer, right-click the

Web Role project, point to Add, and then click Add Reference.

2.Add references to Microsoft.Synchronization.dll, Microsoft.Synchronization.Data.dll, and Microsoft.Synchronization.Data.SqlServer.dll from Sync Framework 2.1

installation folder most of the time it is C:\Program Files (x86)\Microsoft Sync Framework\2.1.

3.Select all files and take the Properties window, then set the value of Aliases property to global and

Copy Local property to True.

4.Create a class file named activationcontext.cs file with the following content and add the file to

Workerrole/Webrole project.

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Runtime.InteropServices;
using System.IO;

namespace Microsoft.Samples.Synchronization
    public class ActivationContext
        // Activation Context API Functions

        [DllImport("Kernel32.dll", SetLastError = true)]
        private extern static IntPtr CreateActCtx(ref ACTCTX actctx);

        // Activation context structure
        private struct ACTCTX
            public int cbSize;
            public uint dwFlags;
            public string lpSource;
            public ushort wProcessorArchitecture;
            public ushort wLangId;
            public string lpAssemblyDirectory;
            public string lpResourceName;
            public string lpApplicationName;

        private const int ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID = 0x004;
        private const int ACTCTX_FLAG_SET_PROCESS_DEFAULT = 0x00000010;
        private IntPtr m_hActCtx = (IntPtr)0;
        public const UInt32 ERROR_SXS_PROCESS_DEFAULT_ALREADY_SET = 14011;

     /// <summary>
     /// Explicitly load a manifest and create the process-default activation
     /// context. It takes effect immediately and stays there until the process exits.
    /// </summary>
        static public void CreateActivationContext()
            string rootFolder = AppDomain.CurrentDomain.BaseDirectory;
            string manifestPath = Path.Combine(rootFolder, "webapp.manifest");
            UInt32 dwError = 0;

            // Build the activation context information structure
            ACTCTX info = new ACTCTX();
            info.cbSize = Marshal.SizeOf(typeof(ACTCTX));
            info.dwFlags = ACTCTX_FLAG_SET_PROCESS_DEFAULT;
            info.lpSource = manifestPath;
            if (null != rootFolder && "" != rootFolder)
                info.lpAssemblyDirectory = rootFolder;
                info.dwFlags |= ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID;

            dwError = 0;

            // Create the activation context
            IntPtr result = CreateActCtx(ref info);
            if (-1 == result.ToInt32())
                dwError = (UInt32)Marshal.GetLastWin32Error();

            if (-1 == result.ToInt32() &&
                string err = string.Format("Cannot create process-default win32 sxs context,
error={0} manifest={1}", dwError, manifestPath);
                ApplicationException ex = new ApplicationException(err);
                throw ex;

5.Add a folder named synchronization.assemblies to the Web Role/ Worker Role project and add the following five files to the folder.


 Create a file named synchronization.assemblies.manifest, add the following content, and add the file to this folder.

 <?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
<file name = "synchronization21.dll">
<comClass clsid="{EC413D66-6221-4ebb-AC55-4900FB321011}"

6.Multiple-select all files under synchronization.assemblies folder, right-click, and then click Properties.

Set the value of Build Action property to Content and Copy To Output Directory to Copy Always.

7.Create a file named webapp.manifest, add the following content, and add the file to the Web Role project.

<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity name="webapp" version="" type="x64"/>
<assemblyIdentity name="synchronization.assemblies" version="" type="x64"/>

 8.Set the value of Build Action property to Content and Copy To Output Directory to Copy Always for the webapp.manifest file using Properties window.

9.Add the following statement to the OnStart method before base.OnStart method call in the WebRole.cs file.


Import contacts from Gmail using ASP.Net/C# Application

October 3, 2011 17 comments

How to import contacts from GMAIL into ASP.Net/C# application

Some of the application especially social network application needs to have the feature for import contacts from our gmail account. By using this feature we can easily import all contacts from our gmail account and can send bulk mail to all or groups in our gmail account

 Is it possible import contacts from GMAIL account using ASP.Net/C# Application?

Of course, we can access and import our gmail contacts into our ASP.Net/C# application using gmail API. GMAIL itself providing some APIs to access gmail accounts from an external applications like ASP.Net or C#. We can call this API from our application by passing our gmail credentials, then will access our account from the application. Here we are demonstrating how we can use GMAIL API to get contacts in GMAIL account using ASP.Net/C# application.

 Very simple Steps to import GMAIL contacts from ASP.Net/C# application

Step-1:  Download Google data API setup.

 Here is the proper link for downloading particular API.

 In this link GMAIL providing so many APIs for communicating with their different project.

 Google.GData.Apps.dll, Google.GData.Client.dll, Google.GData.Contacts.dll, Google.GData.Extensions.dll are the major dll that’s should use for our application.

 Step-2:  Create a very simple ASP.Net application to import contacts from GMAIL. For a simple application, aspx page looks like this

 <html xmlns="">
<head runat="server">
<title>IMport Gmail Contacts</title>
<form id="frmGmailContacts" runat="server">
<asp:TextBox ID="txtUsername" runat="server"></asp:TextBox>
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password">
<asp:Button ID="btnImport" runat="server" Text="Import"
onclick="btnImport_Click" />
<asp:GridView ID="gdvContacts" runat="server"></asp:GridView>

Step 3 : In code behind we have to call API for getting contacts on button click event, and assign result set to gridview.


public static DataSet GetGmailContacts(string App_Name, string Uname,
string UPassword)
DataSet ds = new DataSet();
DataTable dt = new DataTable();
DataColumn C2 = new DataColumn();
C2.DataType = Type.GetType("System.String");
C2.ColumnName = "EmailID";
RequestSettings rs = new RequestSettings(App_Name, Uname, UPassword);
rs.AutoPaging = true;
ContactsRequest cr = new ContactsRequest(rs);
Feed<Contact> f = cr.GetContacts();
foreach (Contact t in f.Entries)
foreach (EMail email in t.Emails)
DataRow dr1 = dt.NewRow();
dr1["EmailID"] = email.Address.ToString();
return ds;
protected void Button1_Click(object sender, EventArgs e)
DataSet ds = GetGmailContacts("Import GMAIL Contacts",
txtUsername.Text, txtPassword.Text);
gdvContacts.DataSource = ds;
%d bloggers like this: