I have a asp.net website folder namely Website3
inside website3
folder there is a upload folder. I want to delete files inside upload folder on button click event.
MY directory status :
Website3 > upload
I'm using the following command but it doesn't delete the file from upload directory
Protected Sub ListView1_ItemDeleted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewDeletedEventArgs) Handles ListView1.ItemDeleted
Dim lab As Label = CType(ListView1.Items(ListView1.SelectedValue).FindControl("photoLabel"), Label)
System.IO.File.Delete(System.IO.Path.GetDirectoryName("/upload/") & lab.Text)
End Sub
您应该使用Server.MapPath
File.Delete((MapPath(".") + ("\\" + lab.Text)))
Just try this:
Public Function DelAllUploadedFiles()
For Each Uploadedfiles As var In System.IO.Directory.GetFiles(Server.MapPath("~/upload/"))
System.IO.File.Delete(Uploadedfiles )
Next
End Function
首先你要在服务器上设置文件夹设置谁可以进入这个文件夹并且有删除权限登录到你的服务器帐户,给每个人文件夹删除权限
Try to put try and catch and see if you have Exception . In general in order to delete in IIS process pool ,should be defined under strong user .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.