Monday, February 9, 2015

SendEmail

 public void SendEmail(string email, string body, string subject, string sender)
    {
        if (email.Trim() != "" && email.Trim() != " ")
        {
            if (isEmail(email))
            {
                try
                {
                    System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
                    if (sender != "")
                    {
                        message.From = new MailAddress(sender);
                    }
                    else
                    {
                        message.From = new MailAddress("serviceteam@julyservices.com");
                    }

                    var emails = email.Split(new Char[] { ',', ';' });
                    foreach (var to in emails)
                    {
                        if (!String.IsNullOrEmpty(to))
                            message.To.Add(new MailAddress(to));
                    }

                    message.To.Add(new MailAddress(email));
                    message.Subject = subject;
                    message.Body = body;
                    message.Priority = System.Net.Mail.MailPriority.High;
                    message.IsBodyHtml = true;

                    //SmtpClient smtpClient = new SmtpClient("mail.texaspension.com");
                    //smtpClient.UseDefaultCredentials = true;

                    System.Net.Mail.SmtpClient smtpClient = new SmtpClient();
                    smtpClient.Host = "mail.julyservices.com";
                    System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential("dp_smtp", "Dp$123456", "julyservices");
                    smtpClient.Credentials = SMTPUserInfo;
                    smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;

                    smtpClient.Send(message);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
    }

Upload a file in ASP.NET

http://www.codeproject.com/Articles/1757/File-Upload-with-ASP-NET

public string UploadPersonalFile(HttpPostedFile myFile, string ContactID)
        {
          
            proposalcenterfunctions proposalfunctions = new proposalcenterfunctions();
this.strRootFilePath = @"" + ConfigurationManager.AppSettings["CensusDataFilesParentDirectory"];

            ProjectPath = "Contacts\\" + ContactID;
            PhysicalDirPath = strRootFilePath + ProjectPath;
            DirectoryInfo clientDir = new DirectoryInfo(PhysicalDirPath);
            if (clientDir.Exists == false)
            {
                clientDir.Create();
            }
            // Get size of uploaded file
            int nFileLen = myFile.ContentLength;
            try
            {
                // make sure the size of the file is > 0
                if (nFileLen > 0)
                {
                    // Allocate a buffer for reading of the file
                    byte[] myData = new byte[nFileLen];
                    // Read uploaded file from the Stream
                    myFile.InputStream.Read(myData, 0, nFileLen);
                    // Create a name for the file to store
                    string strFilename = Path.GetFileName(myFile.FileName);
                    string Extension = strFilename.Remove(0, strFilename.LastIndexOf('.'));
                    string fileName = strFilename.Substring(0, strFilename.Length - Extension.Length);
                    var dateTime = DateTime.Now.ToString("MMddyy_hh-mm-ss");
                    strFilename = fileName + "_" + dateTime + Extension;
                    strFullFilePath = PhysicalDirPath + "\\" + strFilename;
                    proposalfunctions.WriteToFile(strFullFilePath, ref myData);
                }
                else
                {
                    strFullFilePath = "";
                }
            }
            catch (Exception ex)
            {
                ExceptionLogger.WriteLog(ex, "UploadFile");
            }

            return strFullFilePath;
        }



 public void WriteToFile(string strPath, ref byte[] Buffer)
        {
            FileStream stream = new FileStream(strPath, FileMode.Create);
            stream.Write(Buffer, 0, Buffer.Length);
            stream.Close();
        }

Friday, November 14, 2014

MVC-application with Web n Mobile

http://www.asp.net/whitepapers/add-mobile-pages-to-your-aspnet-web-forms-mvc-application

Tuesday, November 4, 2014

Custom Helpers in Asp.net MVC4

http://www.codeproject.com/Tips/832640/Custom-Helpers-in-Asp-net-MVC

Software Design/Architecture



1. Quick overview on object oriented programming and concept.

2. What is software design?

3. What is software architecture? What are roles of a software architecture?

4. Who needs an architect?

5. Is design dead?

6. Refactoring – What, Why, When & How?

7. What is code smell and types of code smell?

8. Unit Testing and Test Driven Development overview

9. Design Patterns:

a. Creational Patterns

i. Abstract Factory

ii. Builder

iii. Factory Method

iv. Prototype

v. Singleton

b. Structural Patterns

i. Adapter

ii. Bridge

iii. Composite

iv. Decorator

v. Façade

vi. Flyweight

vii. Proxy

c. Behavioral Patterns

i. Chain of Responsibility

ii. Command

iii. Interpreter

iv. Iterator

v. Mediator

vi. Memento

vii. Observer

viii. State

ix. Strategy

x. Template Method

xi. Visitor

10. Design Principles

a. Single Responsibility Principle (SRP)

b. Open Closed Principle (OCP)

c. Liskov Substitution Principle (LSP)

d. Interface Segregation Principle (ISP)


e. Dependency Inversion Principle (DIP)

f. DRY – Don’t Repeat yourself

g. Once and only once

h. Tell Don’t Ask

i. The Law of Demeter

j. Inversion of Control

k. Dependency Injection