본문 바로가기
프로그래밍/C#.NET

[1-2]C# Email 보내기(blob 첨부파일 포함) 정리(C# email attachment blob)

by Daily Investing 2012. 10. 24.
반응형

[1-2]window service를 이용해서 C# Email 보내기(blob 첨부파일 포함)

3.  마이플랫폼(UI)을 이용해서 BLOB 데이터 입력

A. 마이플랫폼에서 BLOB 으로 파일을 읽은 후 그 데이터를 C# 으로 넘겨서 BLOB 에 INSERT 를 한다.

MiPlatform source

function AddFileToList(fullPath)
{
        file.FileName = fullPath;
        file.Open();
 
        var arrPath  = Split(fullPath,"\\");
        var argFileName = arrPath[Length(arrPath)-1];
        var fileData = file.ReadBinary();

        var rowIndex;

        rowIndex  = DS_FILE.AddRow();
 
        DS_FILE.SetColumn(rowIndex, "FILE_SEQ" , rowIndex + 1    );
        DS_FILE.SetColumn(rowIndex, "FILE_NAME", argFileName     );
        DS_FILE.SetColumn(rowIndex, "FILE_SIZE", Length(fileData));
        DS_FILE.SetColumn(rowIndex, "FILE_DATA", fileData        );    
        DS_FILE.SetColumn(rowIndex, "SAVE_NAME", ""              );
        DS_FILE.SetColumn(rowIndex, "FILE_PATH", fullPath        );
        DS_FILE.SetColumn(rowIndex, "FILE_TYPE", "F"       );
}

* FILE_DATA 는 BLOB Type 으로 셋팅한다.

 

 C#.NET Source

public void Insert_UploadFile(ref DbTransactionHelper dbTransactionHelper, DataRow dr, DataTable dtAttach, string strReYn)
         {
             try
             {
                 if (dtAttach == null)
                     return;

                 for (int i = 0; i < dtAttach.Rows.Count; i++)
                 {
                     DataRow drAttach = dtAttach.Rows[i];

                     StringBuilder sb = new StringBuilder();

                     sb.Append("INSERT INTO UPLOAD_FILE                     \n");
                     sb.Append("     (PLANT, APPROVAL_NO, APPROVAL_SEQ, APPROVAL_TYPE, 
                                      FILE_SEQ              \n");
                     sb.Append("      , FILE_TYPE, FILE_NAME, FILE_PATH, FILE_SIZE, FILE_DATA    
                                       \n");
                     sb.Append("     )                                   \n");
                     sb.Append("     VALUES ('" + dr["PLANT"].ToString() + "'                  \n");
                     sb.Append("             , '" + dr["APPROVAL_NO"].ToString() + "'          \n");

                     if ("N".Equals(strReYn))
                         sb.Append("             , '" + dr["APPROVAL_SEQ"].ToString() + "'            \n");
                     else
                         sb.Append("             , '" + dr["NEW_APPROVAL_SEQ"].ToString() + "'    \n");

                     sb.Append("             , '" + dr["APPROVAL_TYPE"].ToString() + "'        \n");
                     sb.Append("             , '" + drAttach["FILE_SEQ"].ToString() + "'          \n");
                     sb.Append("             , '" + drAttach["FILE_TYPE"].ToString() + "'        \n");
                     sb.Append("             , '" + drAttach["FILE_NAME"].ToString() + "'       \n");
                     sb.Append("             , '" + drAttach["FILE_PATH"].ToString() + "'        \n");
                     sb.Append("             , '" + drAttach["FILE_SIZE"].ToString() + "'         \n");
                     sb.Append("             , :file_data                                                      \n");
                     sb.Append("            )                      \n");

                     int nParam = dbTransactionHelper.AddParameter(":file_data", drAttach["FILE_DATA"]);

                     string query = sb.ToString();

                     int appliedCnt = dbTransactionHelper.ExecuteNonQuery(query);
                     if (appliedCnt == 0) throw new Exception("No row applied");
                 }
             }
             catch (Exception ex)
             {
                 throw new Exception(ex.Message);
             }
         }

 

위 빨간 부분에 BLOB 를 넣어주면 된다. (dbTransactionHelper sms 는 프로젝트 공통 클래스이다.)

 

 

 

반응형