Custom Aspx Page for MS CRM 2011

Custom Aspx Page for MS CRM 2011 To Create Record in MS CRM

Step 1:

Take an Aspx Page with the Name Lead.aspx

Step 2:

Take a new class with name “OrgService.cs” and write the following code

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.ServiceModel.Description;

using Microsoft.Xrm.Sdk;

using Microsoft.Xrm.Sdk.Client;

using Microsoft.Xrm.Sdk.Metadata;

using Microsoft.Xrm.Sdk.Messages;

using System.Net;

using System.Web.Services.Protocols;

// <summary>

/// Summary description for OrganizationService

/// </summary>

public class OrgService

{

string serverUri = string.Empty;

public OrgService()

{

}

publicstaticIOrganizationService getOrgService()

{

try

{

//Authenticate using credentials of the logged in user;

ClientCredentials Credentials = newClientCredentials();

Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials

//This URL needs to be updated to match the servername and Organization for the environment.

Uri OrganizationUri = new Uri(http://<SERVERURL>/<ORGNAME>/XRMServices/2011/Organization.svc);

OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(serverUrl, null, cliCredentials, null);

IOrganizationService service = (IOrganizationService)serviceProxy;

serviceProxy.EnableProxyTypes();

return service;

}

catch (SoapException ex)

{

throw ex;

}

}

}

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.ServiceModel;

using Microsoft.Xrm.Sdk;

using Microsoft.Xrm.Sdk.Client;

using Microsoft.Xrm.Sdk.Query;

using Microsoft.Xrm.Sdk.Discovery;

public partialclassLead : System.Web.UI.Page

{

IOrganizationService service = OrgService.getOrgService();

protectedvoid Page_Load(object sender, EventArgs e)

{

}

publicvoid CreateLead()

{

Entity lead = newEntity(“lead”);

lead[“firstname”] = txtFName.Text.ToString();

lead[“lastname”] = txtLName.Text.ToString();

lead[“companyname”] = txtCName.Text.ToString();

Guid leadId = service.Create(lead);

}

protectedvoid Button1_Click(object sender, EventArgs e)

{

CreateLead();

}

}

Now Check in CRM Lead , Your Lead has Created

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s