1.需求是:各项目上传照片后,该照片会自动重命名为:项目名称+时间戳
2.在该表的表事件BeforeAttachFile里面写了代码,但是上传图片后没有重命名,图片还是原名称
代码如下:
Dim now As String = Format(Date.now, "yyyyMMddHHmmss")
Dim dr As DataRow = e.DataRow
If dr.IsNull("项目名称") Then
MessageBox.Show("请先输入项目名称!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
e.Cancel = True
Else
e.FileName = dr("项目名称") & now & ".jpg"
End If
在beforeupload事件里面写代码?有参考代码不?
设计窗口,按钮,比如添加一个上传按钮,代码比如
dim r as row = tables("表A").current
if r is nothing then return
Dim dlg As New OpenFileDialog '定义一个新的OpenFileDialog
dlg.Filter= "图片文件|*.jpg" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
Dim now As String = Format(Date.now, "yyyyMMddHHmmss")
dim name as string = r("项目名称") & now & ".jpg"
Dim ftp1 As New FtpClient
ftp1.Host="196.128.143.28"
ftp1.Account = "foxuser"
ftp1.Password = "138238110"
If ftp1.Upload(dlg.FileName,name ) = True Then
Messagebox.show("上传完成!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
Else
Messagebox.show("上传失败!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
End If
End If