在BeforeConnectOuterDataSource事件中有如下代码:
Dim ipfile As String = projectpath & "ip.txt" '定义Ipfile为配置文件
If filesys.FileExists(ipfile) = True Then '先检测是否有Ip.txt这个配置文件
Dim dbfile As String = filesys.ReadAllText(ipfile) '将dbfile定义为配置文件的内容,即数据库的路径
If filesys.FileExists(dbfile) = True Then '若指定的数据库存在
If e.name ="Access" Then
e.C & dbfile & ";Persist Security Info=False"
End If
Else '若配置文件里的内容的指向不正确,即没有找到数据库文件
If e.name ="Access" Then
Dim dlg As new OpenFileDialog
dlg.Filter = "Access文件|*.mdb"
If dlg.ShowDialog = DialogResult.OK Then
e.C & dlg.filename & ";Persist Security Info=False"
filesys.WriteAllText(ipfile,dlg.filename,False)
End If
End If
End If
Else
If e.name = "Access" Then
Dim dlg As new OpenFileDialog
dlg.Filter = "Access文件|*.mdb"
If dlg.ShowDialog = DialogResult.OK Then
e.C & dlg.filename & ";Persist Security Info=False"
filesys.WriteAllText(ipfile,dlg.filename,False)
End If
End If
End If
在项目文件发布时把IP.txt文件添加到了附件中,但执行发布后的项目时,还是要选数据库文件。如果把IP.txt文件复制到publish文件夹里就能正常打开。请问老师这是为什么?