我必须从文件夹中获取2种不同文件类型的列表,并以表格格式显示在电子邮件正文中。 [英] I have to get a list of 2 different file types from a folder and display it in the body of an email in table format.

查看:122
本文介绍了我必须从文件夹中获取2种不同文件类型的列表,并以表格格式显示在电子邮件正文中。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须从文件夹中获取2种不同文件类型的列表,并以表格格式显示在电子邮件正文中。我的代码是:



  Dim  dat_files 作为 字符串()= Directory.GetFiles(  C:\〜  * .dat
Dim ctl_files As String ()= Directory.GetFiles( C:\〜 * .ctl

对于 每个 ctlfiles ctl_files
For 每个数据文件 dat_files
电子邮件(datfiles,ctlfiles)
下一步

下一页





电子邮件的代码是:



 公开 共享 电子邮件(< span class =code-keyword> ByVal  datfiles, ByVal  ctlfiles)
' 一些代码
Dim str As StringBuilder

Dim index 作为 整数 = 0

index< datfiles.Count index< ctlfiles.Count
str.Append( < tr>
str.Append( < td>& datfiles.ElementAtOrDefault(index)& < / td>
str.Append( < td>& ctlfiles.ElementAtOrDefault(index)& < / td>
str.Append( < / tr>

index + = 1
结束 while
objMail.Body = sb.ToString





这不起作用。问题是没有得到所有的数据和邮件中的ctl文件因此无法在两个不同的列中显示它们。任何人都可以帮忙。

解决方案

这是''或''。



   index< datfiles.Count  index< ctlfiles.Count 





当您完成对这两个对象中任何一个对象的内容的评估后,此While语句将退出。按理说,在While退出后,其他对象中可能会有未评估的项目。


我的解决方案:



< pre lang =vb> 模块 Module1

Sub Main()

Dim dat_files As String ()= Directory.GetFiles( C:\\\ * .dat
Dim ctl_files 作为 字符串()= Directory.GetFiles( C:\\\ *。ctl
电子邮件(dat_files,ctl_files)

结束 Sub


公开 Sub 电子邮件( ByVal datfiles 作为 字符串(), ByVal ctlfiles 作为 < span class =code-keyword> String ())

Dim sb 正如 System.Text.StringBuilder

Dim index 作为 整数 = 0

index< datfiles.Length index< ctlfiles.Length
sb.Append( < tr>
sb.Append( < td>& Path.GetFileName(datfiles(index))& ; < / td>
sb.Append( < td>& Path.GetFileName(ctlfiles(index))& < / td>
sb.Append( < / tr>

index + = 1
结束
objMail.Body = sb.ToString
结束 Sub
结束 模块


I have to get a list of 2 different file types from a folder and display it in the body of an email in table format. My code is:

Dim dat_files As String() = Directory.GetFiles("C:\~", "*.dat")
            Dim ctl_files As String() = Directory.GetFiles("C:\~", "*.ctl")

            For Each ctlfiles In ctl_files
                For Each datfiles In dat_files
                    Email(datfiles, ctlfiles)
                Next

            Next



And the code for email is:

Public Shared Sub Email(ByVal datfiles, ByVal ctlfiles)
'some code
 Dim str As New StringBuilder

            Dim index As Integer = 0

            While index < datfiles.Count Or index < ctlfiles.Count
                str.Append("<tr>")
                str.Append("<td>" & datfiles.ElementAtOrDefault(index) & "</td>")
                str.Append("<td>" & ctlfiles.ElementAtOrDefault(index) & "</td>")
                str.Append("</tr>")

                index += 1
            End While
            objMail.Body = sb.ToString



This is not working. The problem is am not getting all the dat & ctl files in the mail thus cannot display them in two different columns.Can anyone help.

解决方案

It''s the ''Or''.

While index < datfiles.Count Or index < ctlfiles.Count



This While statement will exit when you have finished evaluating the contents of either one of those two objects. It stands to reason that there may be unevaluated items in the other object after the While exits.


My solution:

Module Module1

  Sub Main()

    Dim dat_files As String() = Directory.GetFiles("C:\test\", "*.dat")
    Dim ctl_files As String() = Directory.GetFiles("C:\test\", "*.ctl")
    Email(dat_files, ctl_files)

  End Sub


  Public Sub Email(ByVal datfiles As String(), ByVal ctlfiles As String())

    Dim sb As New System.Text.StringBuilder

    Dim index As Integer = 0

    While index < datfiles.Length Or index < ctlfiles.Length
        sb.Append("<tr>")
        sb.Append("<td>" & Path.GetFileName(datfiles(index)) & "</td>")
        sb.Append("<td>" & Path.GetFileName(ctlfiles(index)) & "</td>")
        sb.Append("</tr>")

        index += 1
    End While
    objMail.Body = sb.ToString
      End Sub
End Module


这篇关于我必须从文件夹中获取2种不同文件类型的列表,并以表格格式显示在电子邮件正文中。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆