我有bool将文件添加到ListBox:
If sp.ShowDialog() = DialogResult.OK Then
For Each wp In sp.FileNames
ListBox1.Items.Add(wp)
Next wp
End If
和bool将文件添加到电子邮件中:
If ListBox1.Items.Count <> 0 Then
For Each file In ListBox1.Items
attch = New System.Net.Mail.Attachment(file)
message.Attachments.Add(attch)
Next file
End If
是否可以在ListBox中仅显示文件名,但是它将包含在第二个bool中使用它的路径?
因为我使用sp.SafeFileNames时无法发送它,因为我没有路径。
答案 0 :(得分:0)
您可以使用Imports System.IO
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' add some selected files and show only their name in list
Dim dialog As New OpenFileDialog
If dialog.ShowDialog() <> DialogResult.OK Then Return
Dim attachments = dialog.FileNames.Select(function(s) new Attachment(s)).ToArray()
ListBox1.Items.AddRange(attachments)
ListBox1.DisplayMember = "FileName"
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
' do something with the attachments
Dim attachments = ListBox1.Items.Cast (Of Attachment)
For Each attachment In attachments
Dim fullPath = attachment.FullPath
Console.WriteLine(fullPath)
Next
End Sub
End Class
Public Class Attachment
Public ReadOnly Property FileName As String
Get
Return Path.GetFileName(FullPath)
End Get
End Property
Property FullPath As String
Public Sub New(fullPath As String)
Me.FullPath = fullPath
End Sub
End Class
来展示您的商品:
#include <list>
#include <numeric>
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
list<unsigned long int> primeFactors(unsigned long int n)
{
list<unsigned long int> list;
for (unsigned long int i=2; i <=n; i++)
{
while(n % i == 0)
{
n /= i;
//cout << i << " ";
list.push_back(i);
}
return list;
}
}
int main()
{
unsigned long int n;
list<unsigned long int> plist;
cout << "Enter num: " <<endl;
cin>>n;
plist = primeFactors(n);
for(list<unsigned long int>::iterator it=plist.begin(); it != plist.end(); ++it)
{
cout << ' ' << *it;
cout << '\n ';
}
return 0;
}