Dim f1 As New FileInfo(Server.MapPath("/CaseStudyImages/TemporaryImages/"))
Dim f2 As New FileInfo(Server.MapPath("/CaseStudyImages/" & success & "/"))
Dim dir1 As DirectoryInfo = f1.Directory
Dim dir2 As DirectoryInfo = f2.Directory
Dim Folder1Files As FileInfo() = dir1.GetFiles()
If Folder1Files.Length > 0 Then
For Each aFile As FileInfo In Folder1Files
If File.Exists("f1" & aFile.Name) Then
File.Delete("f2" & aFile.Name)
End If
aFile.MoveTo("f2" & aFile.Name)
Next
End If
Inthis line its showing errror,File.Exists("f1"& aFile.Name)Then
System.UnauthorizedAccessException:Access to the path is denied.
Which part of "Access to the path is denied" you do not understand? File.Exists function requires read permissions on the path that's being checked, you need to sort out permissions.
Dim filepathName As String = HttpContext.Current.Server.MapPath("/CaseStudyImages/" & success & "/")
Dim filepathName2 As String = HttpContext.Current.Server.MapPath("/CaseStudyImages/TemporaryImages/")
Dim dir1 As New DirectoryInfo(filepathName2)
Dim dir2 As New DirectoryInfo(filepathName)
Dim Folder1Files As FileInfo() = dir1.GetFiles()
If Folder1Files.Length > 0 Then
For Each aFile As FileInfo In Folder1Files
aFile.MoveTo(filepathName & aFile.Name)
If File.Exists(filepathName & aFile.Name) Then
File.Delete(filepathName2 & aFile.Name)
End If
Next
End If
Marked as answer by Smadhu on Feb 07, 2012 11:33 AM
Smadhu
Member
511 Points
998 Posts
file.Exists function not working
Feb 07, 2012 10:59 AM|LINK
file.Exists function not working
Dim f1 As New FileInfo(Server.MapPath("/CaseStudyImages/TemporaryImages/")) Dim f2 As New FileInfo(Server.MapPath("/CaseStudyImages/" & success & "/")) Dim dir1 As DirectoryInfo = f1.Directory Dim dir2 As DirectoryInfo = f2.Directory Dim Folder1Files As FileInfo() = dir1.GetFiles() If Folder1Files.Length > 0 Then For Each aFile As FileInfo In Folder1Files If File.Exists("f1" & aFile.Name) Then File.Delete("f2" & aFile.Name) End If aFile.MoveTo("f2" & aFile.Name) Next End IfSystem.UnauthorizedAccessException: Access to the path is denied.i think tprb is with exists functionvytautas.ziu...
Contributor
3854 Points
691 Posts
Re: file.Exists function not working
Feb 07, 2012 11:08 AM|LINK
Which part of "Access to the path is denied" you do not understand? File.Exists function requires read permissions on the path that's being checked, you need to sort out permissions.
Smadhu
Member
511 Points
998 Posts
Re: file.Exists function not working
Feb 07, 2012 11:33 AM|LINK
sorry u were wrong
we have to pass string in exist function
here is the working code
Dim filepathName As String = HttpContext.Current.Server.MapPath("/CaseStudyImages/" & success & "/") Dim filepathName2 As String = HttpContext.Current.Server.MapPath("/CaseStudyImages/TemporaryImages/") Dim dir1 As New DirectoryInfo(filepathName2) Dim dir2 As New DirectoryInfo(filepathName) Dim Folder1Files As FileInfo() = dir1.GetFiles() If Folder1Files.Length > 0 Then For Each aFile As FileInfo In Folder1Files aFile.MoveTo(filepathName & aFile.Name) If File.Exists(filepathName & aFile.Name) Then File.Delete(filepathName2 & aFile.Name) End If Next End If