Click here to Skip to main content
15,915,742 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear Friends,

Here i have Developed one web application and iam saving Pdf files and iam storing that file in one folder.While iam deleting the perticular record.That file which iam storing in folder path it should also but aim getting some Exception error.

The Code:

C#
else if (e.CommandName == "Delete")
     {
         string filename;
         int index = Convert.ToInt32(e.CommandArgument);
         objinfo.IntInformationID = index;
         DataSet ds = objinfo.DeletePdfDocument();
         string strPath = string.Empty;
         filename = ds.Tables[0].Rows[0]["strDocument"].ToString();
         strPath = Server.MapPath("Documents") + "\\" + filename;
         File.Delete(strPath);

         objinfo.GetinfoDelete();
         Response.Redirect("frmManageCode.aspx");
     }




Error is: Access to the path 'D:\AnilKumarBackUp\Developement Center\USAID_EMISICT\ICT_Forms\Documents\DPO12334.pdf' is denied.


if any information regarding this please share with me.


Regards,

AnilKumar.D
Posted

Do the folder which consists of your pdf file have permission for delete??
please check and grant permission to the folder.
another possibility is that your file is already in use.


make it answer if you got your solution.

Thanks
AShish
 
Share this answer
 
Comments
Anil Honey 206 28-Jun-12 7:16am    
i should unCheck the permission through code only.I know in that file properties there is read only is true.Through code i should unchek that.But i dont know how to uncheck
AshishChaudha 28-Jun-12 7:21am    
I think you have to give permission to your folder manually.
Anil Honey 206 28-Jun-12 7:24am    
Manually its not Correct i should uncheck thurough code only.......
AshishChaudha 28-Jun-12 7:26am    
I know that its not correct..ok let me check about your requirement.
This can be because when you request a web page, your webserver is responsible for serving and here the user is your web server and it may not have permission to delete a file from this folder.
Try to change the folder where you save the file to some folder in some subdirectory of your web root folder or give read write permission for your webserver to that particular folder.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900