‏إظهار الرسائل ذات التسميات C#. إظهار كافة الرسائل
‏إظهار الرسائل ذات التسميات C#. إظهار كافة الرسائل

الثلاثاء، 9 فبراير 2016

CRM 2013:Check record duplicate detection Using C# .

 Entity Account= new Entity("account");
            Account["name"] = "Test Account";
            Account["accountnumber"] = "111111111";

Microsoft.Crm.Sdk.Messages.RetrieveDuplicatesRequest req = new Microsoft.Crm.Sdk.Messages.RetrieveDuplicatesRequest
                {
                    BusinessEntity = Account,
                    MatchingEntityName = "account",
                    PagingInfo = new PagingInfo() { PageNumber = 1, Count = 50 }
                };

                Microsoft.Crm.Sdk.Messages.RetrieveDuplicatesResponse resp = (Microsoft.Crm.Sdk.Messages.RetrieveDuplicatesResponse)Service.Execute(req);

                if (resp.DuplicateCollection.Entities.Count > 0)
                    continue;

الخميس، 16 أبريل 2015

How to assign Equipment/Facility to existed resource group.


//********* Create New Equipment/Facility *******************************
        Entity Equipment = new Entity("equipment");
        Equipment["name"]="Test Equipment 1";
        Equipment["timezonecode"]=1;
        Equipment["businessunitid"] = new EntityReference("businessunit", new Guid("BusinessUnitId"));

        Guid EquipmentId = _Service.Create(Equipment);
        //************************** Retrieve the Resource group***************
        Entity ResourceGroup = _Service.Retrieve("constraintbasedgroup", new Guid("ResourceGroupId"), new ColumnSet(true));
        //********************* Get the constrains of Resource group***************
        System.Text.StringBuilder builder = new System.Text.StringBuilder(ResourceGroup["constraints"].ToString());
        //******* Assing the equipment to resouce group ***************
        builder.Replace("</Body>", " || resource[\"Id\"] ==" + EquipmentId.ToString("B") + " </Body>");

        ResourceGroup["constraints"] = builder.ToString();
        //**************************** Update Resource Group***************
        _Service.Update(ResourceGroup);

الأربعاء، 29 يناير 2014

How to use linq with crm 2011 plugin


create XrmServiceContext class
  a- run command prompt 
  b-write the following command "cd C:\Program Files\Microsoft Dynamics CRM\tools" then press enter
  c- write the following command then press enter
        CrmSvcUtil.exe /out:Xrm.cs /url:http://serverName/OrgName/XRMServices/2011/Organization.svc /domain:domainName /username:YourUserName /password:yourPassword /namespace:Xrm /serviceContextName:XrmServiceContext

       (Note:replace the red words with your CRM login configuration)
  d- go to the following path "C:\Program Files\Microsoft Dynamics CRM\tools" and copy "Xrm.cs" file then past to your project.

using (var crm = new XrmServiceContext(service))
 {
       var QuoteProduct = crm.QuoteDetailSet.Where(c => c.QuoteDetailId == QPID).First();
       foreach((var item in QuoteProduct)
      {

      }
}



الاثنين، 30 ديسمبر 2013

How to add System.IO.Packaging reference

add a reference to the WindowsBase Assembly.

CRM 2011:Create a Picklist That Uses a Global Option Set

// Create a picklist attribute   

                PicklistAttributeMetadata pickListAttribute = new PicklistAttributeMetadata();
                // Set base properties
                pickListAttribute.SchemaName = "new_ExampleOptionSet";
                pickListAttribute.DisplayName = new Label("Example OptionSet", 1033);
                pickListAttribute.RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None);
                //pickListAttribute.OptionSet = optionset;
                pickListAttribute.OptionSet = new OptionSetMetadata
                {
                    IsGlobal = true,
                    Name = _globalOptionSetName,
                };
                CreateAttributeRequest createAttribute = new CreateAttributeRequest();

                createAttribute.EntityName = EntityName;
                createAttribute.Attribute = pickListAttribute;
                // Execute the request.
                _Service.Execute(createAttribute);



//************************************************
http://msdn.microsoft.com/en-us/library/gg334416.aspx

الأربعاء، 1 مايو 2013

Send Email Attachment Using Stream

we need to send email with attachment and we didn't need to save this file to computer first and take the path 
of file in function of send email.
to solve this issue:
1-  


public void SendHtmlMail(string To, string Subject, string Body, string AttachFile, byte[] FileStream)
    {
        string SMTPServe = "smtp.gmail.com";
        string From = "email@gmail.com";
        string fromPassword = "password";
        int Port = "587";
        // smtp settings
        MailMessage message = new MailMessage(From, To, Subject, Body);

        message.IsBodyHtml = true;

        Stream ContentStream = new MemoryStream(FileStream);
        if (!string.IsNullOrEmpty(AttachFile))
        {
            System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(ContentStream, Path.GetFileName(AttachFile));
            message.Attachments.Add(attachment);
        }

        var smtp = new System.Net.Mail.SmtpClient();
        {
            smtp.Host = SMTPServe;
            smtp.Port = Port;
            smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
            smtp.Credentials = new NetworkCredential(From, fromPassword);
            smtp.Timeout = 80000;
        }
        try
        {
            smtp.Send(message);
            //return "Your Email has been sent";
        }
        catch(Exception ex)
        {
            throw new Exception(ex.Message);
            //return ex.Message;
        }
    }
}

2-

public static byte[] ConvertStreamToByte(Stream input)
    {
        byte[] buffer = new byte[input.Length];
        //byte[] buffer = new byte[16 * 1024];
        using (MemoryStream ms = new MemoryStream())
        {
            int read;
            while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
            {
                ms.Write(buffer, 0, read);
            }
            return ms.ToArray();
        }
    }

3-

byte[] byteArr = ConvertStreamToByte(FileUpload1.PostedFile.InputStream);
SendHtmlMail(ToEmail, Subject, Body, FileUpload1.FileName, byteArr);


الأحد، 6 يناير 2013

How to: Install and Uninstall Windows Services

* To  Install Or Uninstall Windows Services open Visual studio command Prompt and write this command
      Cd  D:\WindowsService\WindowsService\bin\Debug  
 (Path of WindowsService.exe) then.
1-To Install Windows Service write this Command
           installutil WindowsService.exe
2- To Uninstall Windows Service write this Command
          installutil /u  WindowsService.exe