Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi experts
in my website,users can changer theirs avatar.
but when user has not a image and insert a image for first time is correct,but when there is a image and user changes it i got this error (in local is correct in the server i got error):
Quote:
System.UnauthorizedAccessException
: Access to the path 'D:\Intranet\Portal\User\Pictures\6202.jpg' is denied.


its my code:
C#
var strPath1 = HttpContext.Current.Server.MapPath("~/User/Pictures/") + strFileName;
                                            var strPath2 = HttpContext.Current.Server.MapPath("~/Public/Pictures/") + strFileName;
                                            if (File.Exists(strPathName))
                                            {
                                                HttpContext.Current.Application.Lock();
                                                File.SetAttributes(strPathName, FileAttributes.Normal);
                                                File.Delete(strPathName);
                                                File.Delete(strPath1);
                                                File.Delete(strPath2);
                                                HttpContext.Current.Application.UnLock();
                                            }
                                            oHttpPostedFile.SaveAs(strPathName);
                                            oHttpPostedFile.SaveAs(strPath1);
                                            oHttpPostedFile.SaveAs(strPath2);


i set asp.net permission for folders in server.

Thanks in advance
Posted
Comments
Dholakiya Ankit 31-Aug-13 3:15am    
there is two folder seems to me in which you are updating image and inserting image?
zinajoonjooni 31-Aug-13 6:11am    
i have to upload image in 3 folders.
Dholakiya Ankit 31-Aug-13 7:12am    
name of that one?
idenizeni 31-Aug-13 15:50pm    
In the code you posted you only check the strPathName file exists but then you try to delete three files, are you sure they would all exist based on the one file?
Bernhard Hiller 2-Sep-13 3:26am    
In which line is the error thrown: in
- File.Delete(strPath1);
or in
- oHttpPostedFile.SaveAs(strPath1);
?

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