程序里我是刷新服务器上的图片,根据.net原理是将文件送到本地来显示C:\Documents and Settings\administrator\Local Settings\Temporary Internet Files的目录下面,但是我需要判断该文件是否存在,怎么判断啊???????????????????????????????????
Dim filename As String Dim i as Integer i = Directory.GetFiles("C:\Documents and Settings\administrator\Local Settings\Temporary Internet Files", filename).Length() If Not (File1.PostedFile Is Nothing) Then If i = 0 Then Try File1.PostedFile.SaveAs(sourcedb_name) lblTitle.Text = "上传文件成功!" Catch exc As Exception lblTitle.Text = "上传文件失败,请与管理员联系" Exit Sub End Try Else postedfile = File1.PostedFile lblTitle.Text = "文件已存在,是否替换?" ok.Visible = True cancel.Visible = True End If End If ————————————————————————————————————————————— Private Sub ok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ok.Click ok.Visible = False cancel.Visible = False Try postedfile.SaveAs(sourcedb_name) lblTitle.Text = "上传文件成功!" Catch exc As Exception lblTitle.Text = "上传文件失败,请与管理员联系" End Try End Sub ————————————————————————————————————————————— Private Sub cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cancel.Click ok.Visible = False cancel.Visible = False lblTitle.Text = "文件未上传!" End Sub
System.IO命名空间里有对文件和目录操作的很多类和方法,楼主查查不行了??using System.IO;if(Directory.Exists("file:///C:\\Documents and Settings\\administrator\\Local Settings\\Temporary Internet Files"))//存在 { ........ }
if(Directory.Exists("C://Documents and Settings//Administrator"))//存在 if(Directory.Exists("C://Documents and Settings//Administrator//My Documents"))//不存在 为什么会这样呢????大虾帮助~~~~~是没有权限吗????
if(Directory.Exists("C:\\Documents and Settings\\Administrator")) //存在 if(Directory.Exists("C:\\Documents and Settings\\Administrator\\My Documents")) //不存在
Dim i as Integer i = Directory.GetFiles("C:\Documents and Settings\administrator\Local Settings\Temporary Internet Files", filename).Length() If Not (File1.PostedFile Is Nothing) Then
If i = 0 Then
Try
File1.PostedFile.SaveAs(sourcedb_name)
lblTitle.Text = "上传文件成功!"
Catch exc As Exception
lblTitle.Text = "上传文件失败,请与管理员联系"
Exit Sub
End Try
Else
postedfile = File1.PostedFile
lblTitle.Text = "文件已存在,是否替换?"
ok.Visible = True
cancel.Visible = True
End If
End If
—————————————————————————————————————————————
Private Sub ok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ok.Click
ok.Visible = False
cancel.Visible = False
Try
postedfile.SaveAs(sourcedb_name)
lblTitle.Text = "上传文件成功!"
Catch exc As Exception
lblTitle.Text = "上传文件失败,请与管理员联系"
End Try
End Sub
————————————————————————————————————————————— Private Sub cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cancel.Click
ok.Visible = False
cancel.Visible = False
lblTitle.Text = "文件未上传!"
End Sub
{
........
}
if(Directory.Exists("C://Documents and Settings//Administrator//My Documents"))//不存在
为什么会这样呢????大虾帮助~~~~~是没有权限吗????
if(Directory.Exists("C:\\Documents and Settings\\Administrator\\My Documents")) //不存在
不应将此目录与桌面文件夹本身混淆,后者是虚拟文件夹。
Favorites 用作用户收藏夹项的公共储存库的目录。
History 用作 Internet 历史记录项的公共储存库的目录。
InternetCache 用作 Internet 临时文件的公共储存库的目录。
String strPath = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache);