delete file access denied to the authorized folder(no way out)

N

nasirmajor

dear all,
Please any urgent help regarding following code.
i have the following code

=================================================================
public void Delete(Object sender, DataGridCommandEventArgs e)
{
1 int Sid2 = (int)l.DataKeys[e.Item.ItemIndex];


2 //=======================

3 SqlDataReader gr = null;
4 string engpath2 = "";
5 string arbpath2 = "";

6 gr = db.GetReader("Select * from tbl_SubCat2 Where SId2="
+ Sid2 + "");

7 if (gr.Read())
8 {

9 engpath2 = gr[5].ToString();
10 arbpath2 = gr[6].ToString();

11 }

12 string strfnameeng = Server.MapPath(@"..\" + engpath2);
13 string strfnamearb = Server.MapPath(@"..\" + arbpath2);


14 File.Delete(strfnameeng);
15 File.Delete(strfnamearb);
16 gr.Close();

17 //=================================

18 db.SqlQuery = "Delete from tbl_SubCat2 Where SId2=" + Sid2 + "";

19 db.RunQuery();
20 DataBind();

}

=================================================================
i want the delete command of data grid to delete both the database
field and as well as the file releated to that field as well.

now this is happening separately i.e if last three lines (lines
18,19,20) are removed then file deletion code (line 3 to 16) gets
executed successfully.

and when lines (18,19,20) are again included then field gets deleted
from the database but file could not be deleted and the following error
is generated.

=======
Exception Details: System.UnauthorizedAccessException: Access to the
path 'c:\inetpub\wwwroot\Alreef\' 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) 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.
========


i did go to inetmanager and right click my site and then set the
permissions there but even then there is the same error.
why the whole programme is not going together i.e why line 18,19,20 are
causing errors when they are included with lines(3 to 16)

Please any urgent help.
Thanks in advance
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top