How to download image from url with c#

This code below helping for you

WebClient wc = new WebClient();
wc.UseDefaultCredentials = true;
var image = wc.DownloadData("url"); //byte array

#c-download, #c-image, #image-download, #url-image-download

C# request object(class) convert to xml format

Try this code below;

“myRequestObject” is the request object like wcf service request object.

XmlSerializer serializer = new XmlSerializer(myRequestObject.GetType());
FileStream fs = File.Open("xmlFilePath",FileMode.OpenOrCreate,FileAccess.Write,FileShare.ReadWrite);
serializer.Serialize(fs, myRequestObject);

#c-object-to-xml, #class-to-xml, #xml-format

How to call dynamics crm actions on sdk

Try this code below;

OrganizationRequest oRequest = new OrganizationRequest();
oRequest.RequestName = "action_name";
oRequest["Target"] = new EntityReference("entityname", guid);
oRequest["other_input_parameter"] = "test" // like "name" 

OrganizationResponse orr = service.Execute(oRequest);

#action-call-with-sdk, #actions, #dynamics-365, #dynamics-365-action-call, #dynamics-crm

How to get transaction currency info on dynamics crm

Try this code below;

string currencySymbol = "TRY"; // or something else
QueryExpression qe = new QueryExpression();
qe.EntityName = "transactioncurrency";
qe.ColumnSet = new ColumnSet(true);
qe.Criteria.AddCondition(new ConditionExpression("isocurrencycode", ConditionOperator.Equal, currencySymbol ));

Entity currencyEntity = this.OrgService.RetrieveMultiple(qe).Entities.FirstOrDefault().Id;

#dynamics-crm-transaction-currency, #query-expression-transaction-currency, #transaction-currency

How to send email with attachment in c#

private void SendMailWithoutPortalFieldsInformation(List<string> toList, string fromAddress, string fromTitle, string subject, string portalId, string messageBodyText, string filename, string filemimetype, string filesource)
            MailMessage mailMessage = new MailMessage();
            mailMessage.From = new MailAddress(fromAddress, fromTitle);

            foreach (var item in toList)
                mailMessage.To.Add(new MailAddress(item));

            mailMessage.Subject = subject;
            mailMessage.IsBodyHtml = true;
            mailMessage.Body = messageBodyText;

            SmtpClient smtpClient = new SmtpClient();
            smtpClient.UseDefaultCredentials = false;

            smtpClient.Host = "";
            smtpClient.Port = 123; //Port number
            smtpClient.EnableSsl = true;
            smtpClient.Credentials = new System.Net.NetworkCredential("userame", "password");

            if (!string.IsNullOrEmpty(filename) && !string.IsNullOrEmpty(filemimetype) && !string.IsNullOrEmpty(filesource))
                var fileData = filesource.Replace("data:" + filemimetype + ";base64,", "");
                byte[] bytes = Convert.FromBase64String(fileData);
                Stream stream = new MemoryStream(bytes);
                mailMessage.Attachments.Add(new System.Net.Mail.Attachment(stream, filename, filemimetype));


#c, #email, #email-attacment, #send-mail, #smtp Mvc maximum request length exceeded error

If you receive this error “Maximum request length exceeded.” greater than 4mb file you want to upload. IIS default max file size 4mb. If you want to upgrade max file upload size, this following code will help you.Add to web.config and try again.

<httpRuntime targetFramework="4.5" maxRequestLength="10485760" />

#asp-net-file-upload, #file-size, #file-upload, #file-upload-error, #max-file-size

How to pass list object with ajax request on Mvc

Sample controller and action

 public ActionResult UpdateEmployeePerformance(List<ObjectivesList> ObjectivesList, EmployeePerformance Performance)
     return Json("Ok", JsonRequestBehavior.AllowGet);

Sample Ajax request

	url: "/Custom/UpdateEmployeePerformanceReview",
	type: "POST",
	data: JSON.stringify({ ObjectivesList: updateObjectivesList, EmployeePerformance  : Performance}),
	dataType: "json",
	async: false,
	contentType: "application/json; charset=utf-8",
	beforeSend: function (XMLHttpRequest) {
		XMLHttpRequest.setRequestHeader("Accept", "application/json");
	success: function (data) {
	error: function (XMLHttpRequest, textStatus, errorThrown) {

#ajax-list-parameters-request, #ajax-request, #asp-net-mvc, #jquery