I have a file stream that I want to store in iOS under a subfolder under the SpecialFolder enum.
The FileStream constructor wants the subfolder structure to exist first and when I try to create it, I get UnauthorizedAccessException.
Suppose my intended location is
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/folder1/file1.xls";
which, in my session, resolves to
/var/mobile/Containers/Data/Application/035ECE7D-0E9F-4DF9-927B-B79FB31AEE01/Documents/folder1/file1.xls
Then I make sure the location exists
if (!Directory.Exists(filepath))
{
Directory.CreateDirectory(filepath);
}
which, according to Microsoft, should work
Instead of having the subfolder created and the file stream happily saving the file into it, the CreateDirectory method throws this:
{System.UnauthorizedAccessException: Access to the path "/var/mobile/Containers/Data/Application/035ECE7D-0E9F-4DF9-927B-B79FB31AEE01" is denied.
I thought MyDocuments was free to do stuff in? I've seen no documentation that says I have to apply for permission first. Where should I be creating folders?
If you code with Visual Studio, try to run the program in administrator (Visual Studio), after run your project. Maybe it’s the good solution.
You can try to create platform specific classes for working with saving files and use DependencyService for calling your methods. For iOS app I used this folder enum: Environment.SpecialFolder.Personal and that worked for me.
Related
I'm using the software Inno Setup in order to create an installer for my program, this installs the program to the C:\ProgramFiles(x86) folder, so Im linking my database connection to this new folder, however it won't let me link it as it says I don't have permission.
I am unsure of how to combat this error, as the database is the key part of my program and without it my program wont work.
Putting a database under C:\Program Files or C:\Program Files (x86) is not a good idea. Non-admin users don't have write access to those folder, and you should never give write access to it.
To be Windows conformant, you have two possibilities:
When your program starts the first time, copy a template database to the user's profile under %AppData%\companyname\prgname and use that from now on.
if you need different users to work on the same database, put the database under %ProgramData%\companyname\prgname instead, and don't forget to give user's write access to that folder.
I have migrated an Umbraco install to a new server.
However, I now get a 500 server error whenever I try and open a media file.
I can upload files successfully to the root 'media' folder but I cannot seem to then navigate to these files.
Does anyone know what could be causing this?
As other poeple have mentioned, ideally we need to see the error message. Additionally, can you check if your server can serve up files of that type from other location? If so then it's a permissions issue (check the permissions on the old server match the new one, remember to give read, write and modify permissions to "IIS_IUSRS", "Network Service" and "IUSR" Windows accounts), but if you cannot serve any files of that type at all then you need to add the MIME extensions (added in IIS - see here)
This link suggests touching the global.asax, while this one makes me wonder whether you removed the Label datatype by any chance.
What version of Umbraco are you using? I would also look in the database, in the UmbracoLog table for any errors that might point you in the correct direction.
What type of media files don't work? Is it just certain extensions? Or everything (including images)?
If it is simply certain extensions, you may need to verify that IIS is allowing those extensions.
This might be a dumb question, but I don't seem to be able to create a textfile that is writeable by all the users on a machine, they are always owned by the currently logged in user.
Any ideas? Should I be using TextFile or TFileStream?
I think OP wants to know where to create file writable by all users.
If so, Windows ideology dictates what such files should be created in directory returned by SHGetFolderPath(CSIDL_COMMON_DOCUMENTS) or probabably CSIDL_COMMON_APPDATA
If you create a file it will simply inherit the permissions of its parent container, in other words the folder in which it resides. So you simply need to create it in a folder which has the necessary rights.
What do you mean by "Writable by all the users on a machine" ?
Do you mean you create a file by one user, then another user comes and tries to write into that file, and it fails?
Or do you mean a user creates a file, and other users who are simultaneously connected to the same machine (via terminal sessions) cannot write into the file while the first user is writing in it?
If it is the first case, where is the file saved? Is it in a folder which all users have write access to it?
If it is the second case, you can open the file for read/write without locking it:
var
Stream : TFileStream;
begin
Stream := TFileStream.Create('D:\MyFile',fmOpenReadWrite + fmShareDenyNone);
try
finally
Stream.Free;
end;
end;
Take note with such a code, multiple users might overwrite each other!
Are you talking about NTFS permissions for the file? If yes, you need to look Delphi wrapper for NT security API, and using that API change file security settings to allow Everyone group access the file. If you are just talking about shared access while the file is opened), vcldeveloper above has given the answer.
I have a network folder that is mapped to my iis app as a virtual directory and I'm trying to do some authentication for files that are located there with an ihttpmodule. I've verified that the ihttpmodule is firing properly for anything else in my app, just not the files located in virtual directory. Most of what I've found is that the directory can't be listed as an application (which it isn't), and everything should work. The other solution that I found was to add the the module tag to the tag, but that didn't seem to help either. Everything that I've found talks about stopping this from happening. So my question is what could be set that is causing this to not work? Is there a certain execute permission that needs to be set? Any other iis settings that could cause this? It is an mvc app, and this is how my directory structure is laid out:
server/app <- my application folder
server/app/content/downloads <- downloads is the virtual directory
Do I have to add the virtual directory directly under my app directory? Is that part of the problem? I don't have direct control of the server my code is running on, so testing things out is a bit of a pain... so I was looking for some more thoughts before starting to send emails off to my operations people. Thanks!
Well, I think I found what the issue is.... it looks like by default, iis6 does not pass executables, zip files, or anything of that nature through the .net runtime. It only does that with .aspx files and such, so it will never fire my ihttpmodule. It looks like you can force it to by adding a mapping for that extension, but is there a code work around for this? Or is that the only way?
I have an ASP.NET MVC website that works in tandem with a Windows Service that processes file uploads. For easy maintenance of the site, I'd like the log file for the Windows Service to be accessible (to me, only) via the website, so that I can hit http://myserver/logs/myservice to view the contents of the log file. How can I do that?
At a guess, I could either have the service write its log file in a "Logs" folder at the top level of the site, or I could leave it where it is and set up a virtual directory to point to it. Which of these is better - or is there another, better way?
Wherever the file is stored, I can see that there's going to be another problem. I tried out the first option (Logs folder in my website), but when I try to access the file via HTTP I get an error:
The process cannot access the file 'foo' because it is being used by another process.
Now, I know from experience that my service keeps the file locked for writing while it's running, but that I can still open the file in Notepad to view the current contents. (I'm surprised that IIS insists on write access, if that's what's happening).
How can I get around that? Do I really have to write a handler to read the file and serve it to the browser myself? Or can I fix this with configuration or somesuch?
PS. I'm using IIS7 if that helps.
Unfortunately I'm afraid you'll have to write a handler that will open the file, and return it to the client.
I've written an IIS Manager extension that displays server log files, and what I've noticed that even the simple
System.IO.File.OpenRead("")
can still run in the same problem, and return the same error.. It was kind of confusing.
In the end I used
System.IO.File.Open("", FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
and I could easily open the file while the server was writing logs to it :)
I think the virtual directory is an "okay" solution, if you add the directory (application) with READ ONLY rights + perhaps "BROWSE directory" too (so you can see the folder contents rendered by the IIS).
(But once you do that, you should consider that you also anonymous access to that folder - unless you enable authentication, so watch out for "secret" contents of the logfiles that you might expose? just a thought.)
Another approach, I prefer myself, is to make a MVC/ASP.NET page that does the lookup in the folder by normal code, so that you 100% can filter whatever data is shown in the HTML.
You can open the files as TextStream's and in Read Only mode.
If it's a problem to gain access to the logfolder, I would use the virtual directory with READ ONLY access and then program something that renders the logfiles as HTML on my screen and with my detail levels. Perhaps even add some sort of "login" first. But it all depends on your security levels and contents of logfiles.
is this meaningfull to you? if not, please explain more, as I've been through this thought a few times already for similar situations.