Dev/C#2012. 10. 18. 12:29

아래 코드 참조.
지메일 셋팅 하고, 파일 첨부해서 '비동기' 방식으로 보내기.
(주석처리된 send 는 동기 방식)
한글을 사용하기 위해 제목(subject), 내용(body) 의 인코딩을 UTF8로 셋팅해준다.

  1. using System;  
  2. using System.Windows.Forms;  
  3. using System.Net.Mail;  
  4.   
  5. namespace EmailTestApplication  
  6. {  
  7.     public partial class Form1 : Form  
  8.     {  
  9.         public Form1()  
  10.         {  
  11.             InitializeComponent();  
  12.         }  
  13.   
  14.         private void button1_Click(object sender, EventArgs e)  
  15.         {  
  16.             try  
  17.             {  
  18.                 MailMessage mail = new MailMessage();  
  19.                 SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");  
  20.   
  21.                 //set the address  
  22.                 mail.From = new MailAddress("your g-mail address");  
  23.                 mail.To.Add("target e-mail address");  
  24.   
  25.                 //set the contents  
  26.                 mail.Subject = "Subject Test Mail";  
  27.                 mail.Body = "This is for testing SMTP mail from GMAIL";  
  28.                 mail.BodyEncoding = System.Text.Encoding.UTF8;  
  29.                 mail.SubjectEncoding = System.Text.Encoding.UTF8;  
  30.   
  31.                 //set attachment  
  32.                 System.Net.Mail.Attachment attachment;  
  33.                 attachment = new System.Net.Mail.Attachment("D:\\temp\\file.txt");  
  34.                   
  35.                 mail.Attachments.Add(attachment);  
  36.   
  37.                 //setting smtpServer  
  38.                 SmtpServer.Port = 587;  
  39.                 SmtpServer.Credentials = new System.Net.NetworkCredential("your_ID""your_password");  
  40.                 SmtpServer.EnableSsl = true;  
  41.   
  42.                 //SmtpServer.Send(mail);  
  43.                 // MessageBox.Show("mail Send");  
  44.   
  45.                 //async send mail  
  46.                 object userState = mail;  
  47.                 SmtpServer.SendCompleted += new SendCompletedEventHandler(client_SendCompleted);  
  48.                 SmtpServer.SendAsync(mail, userState);  
  49.                   
  50.             }  
  51.             catch (Exception ex)  
  52.             {  
  53.                 MessageBox.Show(ex.ToString());  
  54.             }  
  55.   
  56.         }  
  57.   
  58.           
  59.         void client_SendCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)   
  60.         {  
  61.             //Get the Original MailMessage object  
  62.             MailMessage mail = (MailMessage)e.UserState;  
  63.   
  64.             //write out the subject  
  65.             string subject = mail.Subject;  
  66.   
  67.             if (e.Error == null)  
  68.             {  
  69.                 // Send succeeded   
  70.                 string message = string.Format("Send Mail with subject [{0}]", subject);  
  71.                 MessageBox.Show(message);  
  72.             }  
  73.             else if (e.Cancelled == true)  
  74.             {  
  75.                 string message = string.Format("Send canceld for mail with subject [{0}]", subject);  
  76.                 MessageBox.Show(message);  
  77.             }  
  78.             else  
  79.             {  
  80.                 // log exception   
  81.                 string message = string.Format("Send Mail Fail - Error: [{0}]", e.Error.ToString());  
  82.                 MessageBox.Show(message);  
  83.             }  
  84.   
  85.         }  
  86.   
  87.     }  
  88. }  

Posted by 놀란
Dev/C#2012. 10. 17. 12:13

솔루션, 프로젝트 파일을 공유하여 작업을 할 때, 각자의 셋팅 환경이 필요한 경우가 있었다.
이 때, 각자의 셋팅을 유지하기 위해서 각자 계정으로 분류하길 원했다.

사용한 메소드는

  1. string currentUser =   
  2.      System.Security.Principal.WindowsIdentity.GetCurrent().Name;  
  3.   
  4. if (currentUser.Contains("hyukjoon"))  
  5.   
  6.     //TO DO  

출처 : http://msdn.microsoft.com/en-us/library/sfs49sw0.aspx

Posted by 놀란
Dev/C#2012. 10. 17. 12:00

String.Contains 메소드 사용

  1. // This example demonstrates the String.Contains() method   
  2. using System;  
  3.   
  4. class Sample   
  5. {  
  6.     public static void Main()   
  7.     {  
  8.     string s1 = "The quick brown fox jumps over the lazy dog";  
  9.     string s2 = "fox";  
  10.     bool b;  
  11.     b = s1.Contains(s2);  
  12.     Console.WriteLine("Is the string, s2, in the string, s1?: {0}", b);  
  13.     }  
  14. }  
  15. /* 
  16. This example produces the following results: 
  17.  
  18. Is the string, s2, in the string, s1?: True 
  19. */  

Posted by 놀란
Dev/DB2012. 6. 27. 16:48

Oracle 의 시퀀스(Sequence) 처럼 MS-SQL 에서는 IDENTITY 를 사용하는데,

이를 초기화 하기 위해서는 아래와 같이 해주면 된다.

DBCC CHECKIDENT( [table_name] , RESEED, 0 )

 

이러고 나면 다음번 시작은 1 부터 나오게 된다.

'Dev > DB' 카테고리의 다른 글

[MongoDB] Query (쿼리문)  (0) 2013.03.15
[MongoDB] DataBase 생성  (2) 2013.02.26
[MySQL] Limit 사용법  (1) 2013.02.05
[SQL-SERVER] 특정 테이블의 컬럼 제목 알아내기  (0) 2012.10.22
Posted by 놀란
Dev/C#2012. 6. 19. 18:35

수 계산 중에 올림 값 표현을 위해서 Math.Ceiling 메소드를 사용하게 되었다.

그런데, 부동소수점 으로 인해서 원치 않는 올림이 되는 현상이 발생했다.

ex )

int value = 50;
double percent = 1.1d;
double result = Math.Ceiling(value * percent) ;

50 * 1.1 = 55 이고 올림을 해도 55가 나올 것으로 생각했으나
56 이 나오게 되었다. 알고 보니 부동소수점 밑으로 55.0000000000000007 뭐 이런 식으로 원치 않는 값이 들어와 있었다.

이래 저래 알아본 결과 System.Decimal.Ceiling 을 사용하게 되었다.
c# 에서 제공하는 통화를 위해 제공되고 있는 메소드 이다.

참고 : http://msdn.microsoft.com/ko-kr/library/364x0z75.aspx

 

Posted by 놀란
Dev Web/ASP.NET2012. 5. 23. 15:52
  • IsPostBack - 현재 페이지가 처음 로드했는지, 다시 게시(PostBack) 되었는지 확인
  • ClientScript.RegisterClientScriptBlock - 자바스크립트를 동적으로 웹 페이지에 추가
  • Header - 현재 웹 폼이 <head> 태그 부분을 정의한다.
  • Title - 현재 웹 폼의 제목을 동적으로 설정하거나 가져온다.
  • SetFocus() - 다른 컨트롤의 ID값을 지정해주면 웹 폼이 로드할 때 해당 컨트롤에 포커스가 지정된다.


'Dev Web > ASP.NET' 카테고리의 다른 글

[ASP.NET] Application , Sesson 개체  (0) 2012.05.23
[ASP.NET] Sever 개체  (0) 2012.05.23
[ASP.NET] Request 개체  (0) 2012.05.23
[ASP.NET] Response 개체  (0) 2012.05.23
Posted by 놀란
Dev Web/ASP.NET2012. 5. 23. 15:27
  • Application 개체는 응용 프로그램 영역에서 어떤 값을 저장시켜 놓은 후, 그 값을 웹 페이지 어느 곳에서든지 참조할 수 있는 기능을 가지고 있는 개체이다. 그래서 주로 응용 프로그램 레벨 변수로 많이 사용되고 Application["이름"] = 값; 과 같은 식으로 값을 저장한다.
    • Lock() - 애플리케이션 변수를 잠그는 메서드
    • UnLock() - 잠긴 애플리케이션 변수를 해제하는 메서드
    • Add() - 애플리케이션 변수를 만들 때 사용
    • Application_Start() - 웹 애플리케이션이 시작할 때 발생(웹 사이트에 첫번째 사용자가 방문할 때 발생). Global.asax에서 설정
    • Application_End() - 웹 응용 프로그램이 끝날 때 발생(웹 사이트에서 마지막 사용자가 나간 후 발생). Global.asax에서 설정
  • Session 개체는 단일 사용자 레벨로 어떤 값을 저장하거나 호출하고자 할 때 사용되는 개체로 한 명의 사용자에 대한 정보를 키와 값으로 저장 가능하며 서버 측 메모리에 해당 데이터를 저장한다. Application 변수가 public 하다면 Session 변수는 Private 한 특성을 지닌다.
    • SessionID - 현재 세션의 고유번호 값 반환
    • SessionTimeout - 세션 시간 기록 : 기본값 20분. 더 추가시키거나 줄일 경우 사용
    • Abandon() - 현재 세션 지우기
    • Session_Start() - 한명의 사용자(세션)가 방문할 때 실행
    • Session_End() - 한명의 사용자가 나간 후 실행


'Dev Web > ASP.NET' 카테고리의 다른 글

[ASP.NET] Page 클래스  (0) 2012.05.23
[ASP.NET] Sever 개체  (0) 2012.05.23
[ASP.NET] Request 개체  (0) 2012.05.23
[ASP.NET] Response 개체  (0) 2012.05.23
Posted by 놀란
Dev Web/ASP.NET2012. 5. 23. 15:12
  • Server  개체는 서버 측에 있는 어떤 기능을 웹 페이지에 표시할 때 필요한 기능들을 가지고 있다.
    • MapPath(".") - 현재 파일과 같은 경로 값 반환 : ., ../
    • Execute() - 다른 파일 포함(인클루드)후 제어권 들어옴.
    • Transfer() - 다른 파일 포함(인클루드)후 제어권 넘김.
    • UrlPathEncode() - 넘겨져 온 쿼리 스트링을 유니코드로 변환(한글 처리)
    • ScriptTimeOut - 서버 측에서 현재 ASPX 페이지를 몇 초간 처리할 건지 설정


'Dev Web > ASP.NET' 카테고리의 다른 글

[ASP.NET] Page 클래스  (0) 2012.05.23
[ASP.NET] Application , Sesson 개체  (0) 2012.05.23
[ASP.NET] Request 개체  (0) 2012.05.23
[ASP.NET] Response 개체  (0) 2012.05.23
Posted by 놀란
Dev Web/ASP.NET2012. 5. 23. 14:38
  • Request  개체는 클라이언트 사용자로부터 어떤 값을 입력(요청) 받을 때 사용한다. 사용자가 폼(Post) 또는 하이퍼링크(Get)를 통하여 전송된 값을 받거나, 현재 사용자의 IP 주소를 얻는 등의 정보를 얻고자 할 때 Request 개체의 주요 멤버를 사용한다.
    • QuestString[] - Get 방식으로 넘겨져 온 쿼리스트링 값을 받고자 할 때 사용한다.
    • Form[] - Post 방식으로 넘겨져 온 값을 받고자 할 대 사용한다.
    • Params[] - Get/Post 방식 모두를 받고자 할 때 사용한다.
    • UserHostAddress - 현재 접속자의  IP 주소 문자열을 반환해준다.
    • ServerVariables[] -  현재 접속자의 주요 서버 환경 변수 값을 알려준다.
    • Cookies[] - 저장된 쿠키 값을 가져온다.
    • Url - 현재 웹 페이지의 URL 을 반환해준다.
    • PhysicalApplicationPath - 현재 웹 사이트의 가상 디렉토리의 물리적인 경로를 알려준다.


'Dev Web > ASP.NET' 카테고리의 다른 글

[ASP.NET] Page 클래스  (0) 2012.05.23
[ASP.NET] Application , Sesson 개체  (0) 2012.05.23
[ASP.NET] Sever 개체  (0) 2012.05.23
[ASP.NET] Response 개체  (0) 2012.05.23
Posted by 놀란
Dev Web/ASP.NET2012. 5. 23. 13:53
  • Response - 서버측에서 결과를 클라이언트 측으로 전송하고자 할 때 사용하는 개체.
    • Write() - 클라이언트 페이지에 문자열을 출력함.
    • Buffer - 버퍼링 사용 여부를 결정함. (true / false)
    • Flush() - 현재 버퍼의 내용츨 출력함.
    • Clear() - 현재 버퍼의 내용을 비움.
    • Expires - 현재 페이지의 소멸 시간을 설정한다.
    • Redirect() - 지정된 페이지로 이동한다.
    • End() - 현재 페이지 종료.
    • WriteFile() - 스트림(파일)을 출력한다.
    • Cookies[] - 쿠키를 저장한다.

 


'Dev Web > ASP.NET' 카테고리의 다른 글

[ASP.NET] Page 클래스  (0) 2012.05.23
[ASP.NET] Application , Sesson 개체  (0) 2012.05.23
[ASP.NET] Sever 개체  (0) 2012.05.23
[ASP.NET] Request 개체  (0) 2012.05.23
Posted by 놀란