Trying to use IO.File.Delete in order to delete a file from a website and it says I do not have permission to do so. I am using forms authentication to log in, and have a FileInfo custom web control that has a LoginView control inside of it to display a Delete linkbutton if the logged in user is a member of the "Admins" role. The control is working fine, however when I try to run the delete code in the click event, it gives me a permission error (access denied), and the file path is the correct absolute path. The page also has some upload code and the logged in users are able to upload files to the same directory fine. The file I am wanting to delete is in a subdirectory of where the page is located, and the current directory is set up to allow all logged in users (the 'Users' role and the 'Admins' role). Is there something I am missing? Should I delete the file in a different way?
code in the custom control with the delete code:
Code:Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Me.lblName.Text = _FileName Me.lblSize.Text = _FileSize Me.hlDownload.Text = _LinkText Me.hlDownload.NavigateUrl = _FileURL 'find the link button in the loginview control, give it text so it is viewed Dim lnkBtnDelete As LinkButton = _ DirectCast(Me.AdminView.FindControl("lnkbtnDelete"), LinkButton) lnkBtnDelete.Text = "Delete" 'add the handler for the delete button click AddHandler lnkBtnDelete.Click, AddressOf lnkBtnDelete_Click End Sub Protected Sub lnkBtnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim FiletoDelete As String = Page.Request.PhysicalApplicationPath & "Members\Files\" & IO.Path.GetFileName(_FileURL) IO.File.Delete(FiletoDelete) End Sub




Reply With Quote