0

I have a web service (.asmx) that takes an array of bytes of an image as a parameter and saves the image on our server. It works fine, other than the fact that I cannot do anything with the file afterwards as I apparently don't have the permissions.

When I use FileStream in my code to save the file to my server folder, is there any where in code that I can set read/write/execute permissions?

**EDIT: Our server is a Linux server

I wrote the web service on my Windows machine (Visual Studio 2010) and packaged it in MonoDevelop for deployment to our Linux server. The folder where I store the images is in the same folder as my .asmx file (on the Linux server). Whenever my web service stores an image in that folder the permission default to rw-------. I would like them to default to rwxrwxrwx.

Cybermaxs
  • 24,378
  • 8
  • 83
  • 112
PaulG
  • 6,920
  • 12
  • 54
  • 98

2 Answers2

1

try this

// Get a FileSecurity object that represents the
// current security settings.
FileSecurity fSecurity = File.GetAccessControl(strFilePath1);

// Add the FileSystemAccessRule to the security settings.
fSecurity.AddAccessRule(new FileSystemAccessRule("IUSR_SOMESERVER",FileSystemRights.FullControl,AccessControlType.Allow));

// Set the new access settings.
File.SetAccessControl(strFilePath1, fSecurity);

adapt the code to what you want (user, filepath and acl)

Cybermaxs
  • 24,378
  • 8
  • 83
  • 112
  • Forgot to mention that our server is a Linux server. I have edited my question. – PaulG Sep 14 '12 at 20:32
  • Ah ... if I understand well, your web service (hosted in windows) save a file to a folder share (hosted in linux) ? – Cybermaxs Sep 15 '12 at 05:47
  • Yes, the folder itself I created with my credentials and set it to 777 (rwxrwxrwx). But the files being placed in the folder default to (rw-------). Do I have to set permissions for the actual asmx file??? – PaulG Sep 17 '12 at 12:58
  • Sorry, no that's not the situation. My web service is hosted on our Linux server (I used Mono Develop to package my c# project). The Images folder is in the same folder as my asmx file. Please see my edit above. Thanks! – PaulG Sep 17 '12 at 13:39
  • 2
    Since this is a Linux Os, I doubt there will be an API in the standardized framework for this. But you can use the Mono.Unix library, specifically the Mono.Unix.Native.Syscall.chmod() method to change the permissions for the created file this. http://docs.go-mono.com/?link=M%3aMono.Unix.Native.Syscall.chmod(System.String%2cMono.Unix.Native.FilePermissions) – Cybermaxs Sep 17 '12 at 13:50
  • Thanks I included the Mono.Posix.dll but the method does nothing in my case, I might not have permission to do this. The OWNER of my asmx file is not the same as the OWNER of the file created by it (the image) why is that?? – PaulG Sep 17 '12 at 18:59
  • The webservice has it's own user. The asmx file was created by the user who installed the service and not the one running it... – SparK Jan 30 '13 at 15:52
0

How do you check for permissions to write to a directory or file?

Here is an article of file permissions, I hope you can apply them to reading the file since it sounds like you do not have trouble writing it or maybe you have trouble writing it properly and that is what causes the permissions to get locked depending on where you save on your server.

Community
  • 1
  • 1
John Sykor
  • 727
  • 5
  • 15