|
-
May 9th, 2013, 10:27 AM
#3
Thread Starter
Frenzied Member
Re: Alternative to System.IO.File.Delete?
 Originally Posted by formlesstree4
How is it not working? I'm assuming some exception is being thrown, correct? If so, post the exception and your code (if possible) so we can work on this problem. There are alternates, but it's silly when it might be something simple that's stopping this from working.
When I try to delete within the RowCommand, I get an Access Denied Error, outside, no Access Denied Error.
i.e. on the same page:
This works where txtTestDelete.Text is hardcoded to "C:\Documents\ACSDocs\Test Document.docx":
Code:
System.IO.File.Delete(txtTestDelete.Text)
This throws:
Access to the path 'C:\Documents\ACSDocs\' is denied.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.UnauthorizedAccessException: Access to the path 'C:\Documents\ACSDocs\' is denied.
ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6 and IIS 7, and the configured application pool identity on IIS 7.5) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.
To grant ASP.NET access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.
Code:
Protected Sub gvFiles_RowCommand(sender As Object, e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvFiles.RowCommand
' Finish Me
' Restrict users to Stephen/Martin
If e.CommandName = "DeleteFile" Then
Dim oSQL As New clsSQL
Dim strFileName As String = ""
oSQL.GetFileName(strFileName, gvFiles.DataKeys(e.CommandArgument).Value())
'Dim strFilePath As String = Server.MapPath("~\ACSDocs\" & strFileName)
Dim strFilePath As String = "C:\Documents\ACSDocs\" & strFileName
System.IO.File.Delete(strFilePath)
oSQL.DeleteACSDocs(gvFiles.DataKeys(e.CommandArgument).Value())
oSQL.LoadACSDocs()
gvFiles.DataSource = oSQL.Dataset.Tables("ACSDocs")
gvFiles.DataBind()
End If
End Sub
It is beyond frustrating. That's kind of why I am ready to try an alternative and move on.
Last edited by SeanGrebey; May 9th, 2013 at 10:31 AM.
Sean
Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|