Thursday, August 29, 2019

Convert javascript array to string

var value = { 1,2,3,7101,1000,36,7133,7140,7140 };
var blkstr = [];
$.each(value, function(idx2,val2) {                 
  var str = val2;
  blkstr.push(str);
});
console.log(blkstr.join(", "));





var arr = [A, B, C];
var arrString = arr.join(", ");

This results in the following output:

A, B, C

Wednesday, August 28, 2019

To get all files in the Folder containing .jpg or mp3 files C#.net

For .NET 4.0 and later,

var files = Directory.EnumerateFiles("C:\\path", "*.*", SearchOption.AllDirectories)
            .Where(s => s.EndsWith(".mp3") || s.EndsWith(".jpg"));
For earlier versions of .NET,

var files = Directory.GetFiles("C:\\path", "*.*", SearchOption.AllDirectories)
            .Where(s => s.EndsWith(".mp3") || s.EndsWith(".jpg"));

Monday, August 26, 2019

Sending email with attachments from C#

To add these namespaces to your code behind file:

1. using System.Net;
2. using System.Net.Mail;

Then write the following method

public void email_send()
{
    MailMessage mail = new MailMessage();
    SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
    mail.From = new MailAddress("your mail@gmail.com");
    mail.To.Add("to_mail@gmail.com");
    mail.Subject = "Test Mail - 1";
    mail.Body = "mail with attachment";

    System.Net.Mail.Attachment attachment;
    attachment = new System.Net.Mail.Attachment("c:/textfile.txt");
    mail.Attachments.Add(attachment);

    SmtpServer.Port = 587;
    SmtpServer.Credentials = new System.Net.NetworkCredential("your mail@gmail.com", "your password");
    SmtpServer.EnableSsl = true;

    SmtpServer.Send(mail);

}

How to test if a DataSet is empty?

this should work for you

if (ds.Tables[0].Rows.Count == 0)
{
    //
}

Tuesday, August 13, 2019

ConfigurationManager Class not exist on .NET 4.5 Framework

An Error


Solution:-
RightClick on project -> Add-> Reference...-> Assemblies-> Framework Select the System.Configuration (checked) Should solve the problem.