In my ASP.Net web application, I have loaded one image on the HTML 5 canvas and allow the user to draw some graphics (rectangle box) over the images. Once the user has finished their drawings on the image I have to save the image back to the server with the same name at same location.
I am using AJAX
to transmit the image data to the server. This part is done successfully.
In my server code, first I am trying to delete a file and then create a new file with the same name at same location.
So, When I am deleting the file, it is raising UnAuthorizedAccessException is handled by user code Access to the path 'D:\vs-2010projects\delete_sample\delete_sample\myimages\page_1.png' is denied.
Here is my Server Side C# Code...
[WebMethod()]
public static void UploadImage(string imageData)
{
byte[] data = Convert.FromBase64String(imageData);
if(File.Exists("D:\\vs-2010projects\\delete_sample\\delete_sample\\myimages\\page_1.png"))
{
File.Delete("D:\\vs-2010projects\\delete_sample\\delete_sample\\myimages\\page_1.png");
}
FileStream fs = new FileStream("D:\\vs-2010projects\\delete_sample\\delete_sample\\myimages\\page_1.png", FileMode.Create);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(data);
bw.Close();
}//UploadImage
Is there any way to delete a file?
Please guide me out of this issue.