الأربعاء، 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);


السبت، 27 أبريل 2013

CRM 2011 Error:Login failed for user 'domain\Userlogin'.


Add the Microsoft Dynamics CRM server to the SQLAccessGroup group in Active Directory. To do this, follow these steps:
  1. Click the organizational unit in which you install Microsoft Dynamics CRM.
  2. Double-click SQLAccessGroup.
  3. In the SQLAccessGroup dialog box, click Members, click Add, click Object Types, click to select the Computers check box, and then click OK.
  4. In the Enter the object names to select box, type the name of the Microsoft Dynamics CRM server, and then click Check Names.
  5. Verify that the name of the Microsoft Dynamics CRM server in the Enter the object names to select box is available, and then click OK two times.
  6. Restart the Microsoft Dynamics CRM server.

الثلاثاء، 19 مارس 2013

Could not load type System.ServiceModel.Activation.HttpModule


  • This error can occur when IIS is installed after installing .NET Framework 4, or if the 3.0 version of the WCF Http Activation module is installed after installing IIS and .NET Framework 4.
    To resolve this problem, you must use the ASP.NET IIS Registration Tool (Aspnet_regiis.exe,) to register the correct version of ASP.NET. This can be accomplished by using the –iru parameters when running aspnet_regiis.exe as follows:

    1- Open Visual studio command prompt.
    2- write this command aspnet_regiis.exe -iru

السبت، 9 فبراير 2013

CRM 2011:The import file is too large to upload.

The error indicates that the file size was above the default max import file size of 8 MB. In order to change 
the default setting please apply the following steps.

Step 1:-

1.Click Start, click Run, type regedit, and then click OK.
2.Locate the following registry subkey:

HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ MSCRM

3.Right-click MSCRM, point to New, and then click DWORD Value to create a new DWORD value.
4.Rename the DWORD value to the following value:
OLEDBTimeout

5.Right-click the DWORD value, and then click Modify.
6.In the Edit DWORD Value dialog box, type 86400 in the Value data box, click Decimal in the Base option, and then click OK. 

7.Right-click MSCRM, point to New, and then click DWORD Value to create a new DWORD value.
8.Rename the DWORD value to the following value:
ExtendedTimeout

9.Right-click the DWORD value, and then click Modify.
10.In the Edit DWORD Value dialog box, type 1000000 in the Value data box, and then click OK. 

--------------------------------------------------
a- Open Web.Config file for CRM web Application
  1. locate the following line.

    <httpRuntime executionTimeout="300" maxRequestLength="8192"/>
    Change executionTimeout="3600" and change maxRequestLength="20000".
    then locate the following line.
    1. <httpRuntime maxRequestLength="8192"/>
    Change maxRequestLength="20000".
    Save and then close the Web.config file.

Step 2:-    

Verify the current value for the "Max" file size for data upload. By default the value is set to "8".

Use MSCRM_CONFIG
select ColumnName, IntColumn from ServerSettingsProperties
where ColumnName = 'ImportMaxAllowedFileSizeInMB'
Go 

change the default value from 8 to 12.

Use MSCRM_CONFIG
UPDATE [MSCRM_CONFIG].[dbo].[ServerSettingsProperties]
SET [IntColumn] = '12'
WHERE ColumnName = 'ImportMaxAllowedFileSizeInMB'
Go

الاثنين، 14 يناير 2013

How To Solve this Problem:a potentially dangerous request.form value was detected from the client...

1- added the following to the existing "page" directive in that .aspx file.
ValidateRequest="false"
2-add requestValidationMode="2.0" to the httpRuntime configuration section of the web.config file like the following:
 <httpRuntime requestValidationMode="2.0"/> 

الثلاثاء، 8 يناير 2013

How To Get Lookup ID,Name and EntityType in CRM 2011

First Write a function to get lookup
    function GetLookup(FieldName) {
    var lookup = Xrm.Page.data.entity.attributes.get(FieldName)
    if (lookup == null) { return null; };
    var lookupObj = lookup.getValue();
    return lookupObj[0];     
 }

1- To Get Lookup Id.
    function GetLookupId(fieldName) {
    var lookup = GetLookup(fieldName);
    if (lookup != null) {
        return lookup.id;
      }
    return null;
  }

2- To Get Lookup Name.
 function GetLookupName(fieldName) {
    var lookup = GetLookup(fieldName);
    if (lookup != null) {
        return lookup.name;
      }
    return null;
  }

3- To Get Lookup Entity Type. 
    function GetLookupEntityType(fieldName) {
    var lookup = GetLookup(fieldName);
    if (lookup != null) {
        return lookup.entityType;
      }
    return null;
  }

الأحد، 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