6

I've written a method on my controller that auto generates a powerpoint deck for my client and all that works fine...except I'm stuck on the part about saving the file to disk.

I'm no stranger to this concept; and "thought" that all I needed to do is grant IIS_IUSRS write permission on the directory and read permission on all parent directories. I'm using IIS 7, and I've done this before with IIS 6 granting NETWORK SERVICE the same permissions.

Just for kicks, I even gave EVERYONE write permissions on the directory and I still keep getting the Exception: System.UnauthorizedAccessException: Access to the path 'C:......\Content\PPT' is denied. (I removed some of the path for simplicity).

Is there anything else I am overlooking? The server it's on is the first one I've set up, so I just may have overlooked something?

Here's my controller method simplified:

public ActionResult CreatePowerPoint()
    {
        string path = HttpContext.Server.MapPath("~/Content/PPT");

        Aspose.Slides.Presentation presentation = new Aspose.Slides.Presentation();
        CreatePresentation(presentation);

        presentation.Save(path, Aspose.Slides.Export.SaveFormat.Ppt);

        return View();
    }
}

the presentation.Save() method takes a path and a save format...I don't know what else to try... Is there something wrong with my code? Am I creating the path incorrectly? I can also pass a Stream stream into the save method, but I am not sure if that will fix the problem.

tereško
  • 58,060
  • 25
  • 98
  • 150
Ben
  • 1,023
  • 7
  • 18
  • 35
  • 1
    The part of the path you decided to omit for convenience may make a difference. You need to show where in the directory tree you're trying to save the file; Windows in some versions doesn't allow non-administrative users to write to some folders as part of UAC. "I can't save to this directory" without showing the directory makes the question pretty unanswerable. – Ken White Mar 13 '11 at 20:50
  • 1
    Or you can try impersonating a User instead of giving IIS_IUSERS or EVERYONE the permissions. I think its not allowed to access all the folders from non-administrative users and that's creating issues. The proper way to go is Impersonation. – Tayyab Mar 13 '11 at 21:06
  • I appreciate the help. I've found the solution I posted in my own response. Thank you also Ken, because the path was correct, but I also needed to have the file name added to the end of the path. – Ben Mar 14 '11 at 18:10
  • See this thread: http://stackoverflow.com/questions/333571/asp-net-system-unauthorizedaccessexception-access-to-path-denied – RichO Mar 13 '11 at 21:04
  • I always appreciate help, but the thread you posted is more about accessing a directory on a separate server; in which the correct approach would be to give an identity in the web config for that server. My problem was about writing to the file system on the same server. None the less, I up-voted your response bc it will hopefully help others. I've updated the question with my final solution; which was to set the identity of the default application pool in IIS 7; I used Network Service as mine. I also didn't have the file name in my path, which was required. – Ben Mar 14 '11 at 18:06

4 Answers4

18

I found the solution - I'm using IIS 7, and I had the application pool set to the wrong identity. In IIS 7, I simply changed the identity of the application pool my app is running on and boom, everything worked. I used NETWORK SERVICE as my identity.

Also for those using Aspose Slides, I also had to make sure the file name was in the path.

Ben
  • 1,023
  • 7
  • 18
  • 35
3

The application pool identity has to be set to "Network Service" (as an example of a valid user you can use to run the service). But you also have to set in IIS Admin Authentication\Anonymous Authentication enabled and Anonymous User Identity to "Application pool identity". Without this I was still gettings access denied exceptions on file upload.

Rudy
  • 939
  • 9
  • 6
3

I ran into this issue, but it was really because the files were marked as Read-Only in the NTFS FS.

In my case, it was a new FileStream(path, FileMode.Open) that was failing, and was easily corrected by replacing that with a File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read).

Bottom line, even if the file is readable, just specifying the FileMode.Open seems to default into FileAccess.ReadWrite.

Mauricio Morales
  • 988
  • 1
  • 9
  • 16
0

I was having same issue, the problem was I did not remove the Read Only checkbox on the properties for the given folder.

Ro.
  • 1,525
  • 1
  • 14
  • 17