2014-09-03 73 views
0

如何不能附加到來自DB行的分割字符串文件名(我需要「mode = 2」和「case 2:」)。 在我的日誌文件中的錯誤:來自DB行的多附加文件

FILE TO ATTACH ERR : Could not find file 'C:\inetpub\wwwroot\PLATFORM_700_NTFSRV\PLATFORM_700_NTFSRV_LAB\Attachments\text.txt,text2.txt'.

這裏我的示例代碼和我排在DB 排在DB:

|FILE_TO_ATTACH  | 
|text1.txt,text2.txt| 

public DataTable GetAttachmentFiles(int mode , string fileIDList) 
    { 
     try 
     { 
       DataTable DTB = new DataTable(); 
      if (mode == 1) 
      { 

       SqlCommand TheCommand = GetCommand("application_MessageAttachFiles", CommandType.StoredProcedure, 
        GetConnection("APP")); 
       TheCommand.Parameters.Add("FILEIDLIST", SqlDbType.VarChar, 8000); 
       TheCommand.Parameters["FILEIDLIST"].Value = fileIDList; 


       SqlDataAdapter SDA = new SqlDataAdapter(); 
       SDA.SelectCommand = TheCommand; 
       SDA.Fill(DTB); 
      } 
      else if(mode == 2) 
      { 
       try 
       { 
        DTB.Columns.Add("FILENAME"); 
        string[] fileList = fileIDList.Split(','); 

        for (int c = 0; c < fileList.Length; c++) 
        { 
         DataRow DR = DTB.NewRow(); 
         DR["FILENAME"] = fileList[c]; 


         DTB.Rows.Add(DR); 
        } 
       } 
       catch (Exception ex) 
       { 
        RecordLine("ERROR Reading GetAttachmentFiles: " + ex.Message); 
       } 

      } 

      return DTB; 
     } 
     catch (Exception eX) 
     { 
      RecordLine("ERROR GetAttachmentFiles : " + eX.Message); 
      return null; 
     } 
    } 

    public Attachment AttachmentFile(int mode, string fileNameString, int fileID, DataRow DRA) 
    { 
     // mode.ToString(ConfigurationSettings.AppSettings["MODE"]); 


     try 
     { 

      switch (mode) 
      { 
       case 1: /*from Database*/ 

        if (DRA != null) 
        { 
         Attachment messageAttachment; 


         int fileDataSize = int.Parse(DRA["FileSize"].ToString()); 
         string fileType = DRA["FileType"].ToString(); 
         string fileName = DRA["FileName"].ToString(); 
         byte[] fileBuffer = (DRA["FileData"]) as byte[]; 


         MemoryStream ms = new MemoryStream(fileBuffer); 

         RecordLine("DEBUG 2 - " + fileName + " " + fileType + " " + fileDataSize.ToString() + " " + ms.Length.ToString() + " buffer size:" + fileBuffer.Length.ToString()); 
         messageAttachment = new Attachment(ms, fileName, fileType); 
         return messageAttachment; 


        } 

        break; 

       case 2: /*from Local Machin */ 
       { 


        Attachment messageAttachment; 
        try 
        { 

         fileNameString = String.Format("{0}\\{1}", ConfigurationSettings.AppSettings["SOURCE_FILE"], 
          fileNameString); 

         messageAttachment = new Attachment(fileNameString); 
         RecordLine("DEBUG 2.1 - " + messageAttachment.Name); 
         return messageAttachment; 
        } 
        catch (Exception ex) 
        { 
         RecordLine("FILE TO ATTACH ERR : " + ex.Message); 
        } 
       } 

        break; 


       default: 
        return null; 
        break; 
      } 


      return null; 




     } 
     catch (Exception eX) 
     { 
      RecordLine("ERROR AttachmentFile : " + eX.Message); 
      return null; 
     } 
    } 

回答

0

我不得不添加此代碼和它的工作:

foreach (DataRow DRA in DTBA.Rows) 
     { 
      message.Attachments.Add(AttachmentFile(2, DRA["FILENAME"].ToString().Trim(), 0, null)); 
      RecordLine("DEBUG 3.1 - " + message.Attachments.Count.ToString()); 
     }