上载档案仅限.doc,.docx,.xls,.xlsx,.pdf,.tif,.tiff,.jpg,.gif,.txt [英] Upload file restricted to .doc, .docx, .xls, .xlsx, .pdf, .tif, .tiff, .jpg, .gif, .txt only
本文介绍了上载档案仅限.doc,.docx,.xls,.xlsx,.pdf,.tif,.tiff,.jpg,.gif,.txt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我有以下代码
Hi All
I have below code
Private Sub btnUpload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpload.Click
If txtDocPath.Text <> "" Then
Dim sqlstr As New StringBuilder
Dim strFileName As String
Dim strFileName1 As String
Dim AppPath As String
'My.Application.Info.DirectoryPath
'For Live
'AppPath = GetIniSetting("RootLocationFileFolder") & "\"
'For Local
''Laksman
AppPath = "E:\LocationFiles\"
Dim FlagSelected As Boolean = False
strFileName1 = ofdDocToUpload.FileName
strFileName = getTimeStamp() & "_" & ofdDocToUpload.SafeFileName()
'strFileName = ofdDocToUpload.SafeFileName()
AppPath = AppPath + strFileName
sqlstr.Append("ESP_InsLocationFiles ")
sqlstr.Append(PrepareString(ChangeToEmptyString(strFileName)) & COMMA)
sqlstr.Append(ChangeToZero(MDS_RECNUM) & COMMA)
sqlstr.Append(PrepareString(txtLocationName.Text.Trim()) & COMMA)
sqlstr.Append(PrepareString(System.DateTime.Now.ToString()))
ExecuteSQLNonQuery(sqlstr.ToString)
sqlstr.Length = 0
FlagSelected = True
If FlagSelected = True Then
FileCopy(strFileName1, AppPath)
MsgBox("Location files uploaded successfully", MsgBoxStyle.Information, "Upload Files")
txtDocPath.Text = ""
populateLocationFiles()
Else
MsgBox("Please select location to upload", MsgBoxStyle.Information, "Upload Files")
Exit Sub
End If
Else
MsgBox("Please select file to upload.", MsgBoxStyle.Information, "Upload Files")
btnBrowse.Select()
Exit Sub
End If
End Sub
允许上传所有类型的FILE,但条件是,上传文件仅限于.doc,.docx,.xls,.xlsx,.pdf,.tif,.tiff,.jpg,.gif,.txt,其中&我应该改变什么?请帮助...
which allow to upload all types of FILE but condition is that Upload file restricted to .doc, .docx, .xls, .xlsx, .pdf, .tif, .tiff, .jpg, .gif, .txt only, where & what should I change? Please help...
推荐答案
确定,因此您将此限制放在OpenFileDialog中 ^ ].
OK, so you put this restriction in your OpenFileDialog Filter property[^].
使用OpenFileDialog是个好主意,但我不认为您正在使用它.
Using OpenFileDialog is a good idea, but I don''t think you are using it.
fdlg.Filter = "Document(*.doc,*.docx)|*.doc;*.docx|Excel(*.xls,*.xlsx)|*.xls;*.xlsx|PDF(*.pdf)|*.pdf|Text(*.txt)|*.txt|Image(*.tif,*.tiff,*.jpg,*.gif)|*.tif;*.tiff;*.jpg;*.gif"
您仍然可以按照以下方式限制文件类型.
Still you can restrict the file types as follows.
Dim allowedTypes() As String = New String() {"doc", "xls", "txt"} ' list types here
If Not allowedTypes.Contains(IO.Path.GetExtension(txtDocPath.Text)) Then
MsgBox("Selected file is not supported.", MsgBoxStyle.Information, "Upload Files")
btnBrowse.Select()
Exit Sub
End If
可能会为您提供帮助.
it may help you.
if (fileExt == ".jpg" || fileExt == ".gif" || fileExt == ".bmp" || fileExt == ".jpeg" || fileExt == ".png" || fileExt==".txt")
{
statement........
statement..........
}
这篇关于上载档案仅限.doc,.docx,.xls,.xlsx,.pdf,.tif,.tiff,.jpg,.gif,.txt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文