Anthony 0

Anthony 0

  • NA
  • 1
  • 0

System.UnauthorizedAccessException

Feb 26 2005 4:17 PM
I've written a web service that accepts a filename and a byte array, opens a FileStream andis supposed to write the file out to the directory. It works if the file doesn't already exist, but if it exists, it kicks back this exception (System.UnauthorizedAccessException). I thought that maybe with the FileStream I couldn't overwrite the file, so I did a File.Exists() to see if the file was there, if it was, I ran File.Delete() on the file, thinking since it would let me write the file if it didn't exist, this would work. But no go. Anybody have any suggestions?? (Code pasted below) [WebMethod] public void uploadFile (string filename, byte[] data) { if (File.Exists(Server.MapPath("appUpdate\\") + filename)) { File.Delete(Server.MapPath("appUpdate\\") + filename); } FileStream fs = File.Create(Server.MapPath("appUpdate\\") + filename); fs.Write(data, 0, data.Length); fs.Close(); } Thanks in advance, Anthony