Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

Can not create a new file with File.Create -- throws exception:     Access Denied

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
thephatp - 28 Mar 2008 04:17 GMT
I'm trying to do something extremely basic, and I don't remember
having these problems in XP.

I'm running a service, logged in as an administrator.  I created a
directory in windows explorer (as administrator), and set all
permissions/security for all users (including the Everyone group) to
full control.

The following code still does not work:

           FileStream fs;
           try
           {

System.Windows.Forms.MessageBox.Show( this.sFileStoreLocation + "\\" +
sFilename + ".txt" );
               fs = File.Create( this.sFileStoreLocation + "\\" +
sFilename + ".txt" );
           }
           catch( Exception e )
           {
               System.Windows.Forms.MessageBox.Show( e.ToString() );
               fs = null;
           }

Any ideas?  Is this a Vista thing?  I don't understand why it is so
difficult to do this right now (and I'm really suspecting Vista).

The scenario I need to work is this:

Any user logs in.  My app starts running.  The user does something and
my app will need to produce some logging.  I check to see a directory
exists in my apps "Program Files" location.  If not, the user needs to
be able to create it.  All users will need to be able to write to this
directory.  (I can't get directory creation to work either, but one
thing at a time--and I assume the solution will fix both problems.)
It will be a general logging location.  The creation of the directory
is still important, because if it happends to get deleted, I want to
try to recreate it, not just be sunk for logging.  And since I
wouldn't doubt one my clients could accidentally delete this folder, I
have to make it work in code.

Thanks,

Chad
Ignacio Machin ( .NET/ C# MVP ) - 28 Mar 2008 20:19 GMT
> I'm trying to do something extremely basic, and I don't remember
> having these problems in XP.
[quoted text clipped - 41 lines]
>
> Chad

Hi

where this.sFileStoreLocation  is pointing to?

And yes, it's possible it's a Vista "feature"
Willy Denoyette [MVP] - 28 Mar 2008 21:56 GMT
> I'm trying to do something extremely basic, and I don't remember
> having these problems in XP.
[quoted text clipped - 41 lines]
>
> Chad

What's the sFileStoreLocation value?
Keep in mind that "administrator" (like all administrators account!) is just
a regular user account , unless you run elevated (which is not the case
here).

Also, using MessageBox.Show (or whatever System;Windows.Forms class method)
is a big NO NO in Vista, if you really need to display a (simple) message
box, you will have to PInvoke the WTSSendMessage API.

Willy.
thephatp - 30 Mar 2008 01:28 GMT
On Mar 28, 3:56 pm, "Willy Denoyette [MVP]"
<willy.denoye...@telenet.be> wrote:

> > I'm trying to do something extremely basic, and I don't remember
> > having these problems in XP.
[quoted text clipped - 54 lines]
>
> - Show quoted text -

The sFileStoreLocation is pointing to a new folder that I created,
like "C:\Temp_NEW\MyFolder\".  I've given all groups full permissions
on this folder, and yet I still get an error.  I could check each
user's temp directory, but I have two issues with that.  In Vista, I'm
getting that the path is:

"C:\Users\MyUser\AppData\Local\Microsoft\Windows\Temporary Internet
Files\Virtualized\C\Users\MyUser\AppData\Local\Temp\Low\"

I'm not familiar with virtualized folders, but I went to Temporary
Internet Files and got what I expected (no `Virtualized` folder ;),
but I also went to `C\Users\MyUser\AppData\Local\Temp\Low\`, but I
didn't see anything there either.  So, knowing nothing about this is
my first problem.  My second problem is that this would mean that I
have to check all user locations for files stored here.  Oh, and I'll
want to create my own folder under this, like `MyAppLogs` so that I
can check them on the fly (in service).  That's a real pain to have to
do that for each user.  I'd like to be able to create a place where
all users can write to, and if the directory happens to get deleted,
that any user can recreate.  However, if necessary, I could have the
background service do so (which would be running as system).

Any help?  FYI, I'm using the System.IO.Path.GetTempPath() method.

Thanks again.
Willy Denoyette [MVP] - 30 Mar 2008 15:48 GMT
On Mar 28, 3:56 pm, "Willy Denoyette [MVP]"
<willy.denoye...@telenet.be> wrote:
> "thephatp" <chad.a.mor...@gmail.com> wrote in message
>
[quoted text clipped - 60 lines]
>
> - Show quoted text -

The sFileStoreLocation is pointing to a new folder that I created,
like "C:\Temp_NEW\MyFolder\".  I've given all groups full permissions
on this folder, and yet I still get an error.  I could check each
user's temp directory, but I have two issues with that.  In Vista, I'm
getting that the path is:

"C:\Users\MyUser\AppData\Local\Microsoft\Windows\Temporary Internet
Files\Virtualized\C\Users\MyUser\AppData\Local\Temp\Low\"

I'm not familiar with virtualized folders, but I went to Temporary
Internet Files and got what I expected (no `Virtualized` folder ;),
but I also went to `C\Users\MyUser\AppData\Local\Temp\Low\`, but I
didn't see anything there either.  So, knowing nothing about this is
my first problem.  My second problem is that this would mean that I
have to check all user locations for files stored here.  Oh, and I'll
want to create my own folder under this, like `MyAppLogs` so that I
can check them on the fly (in service).  That's a real pain to have to
do that for each user.  I'd like to be able to create a place where
all users can write to, and if the directory happens to get deleted,
that any user can recreate.  However, if necessary, I could have the
background service do so (which would be running as system).

Any help?  FYI, I'm using the System.IO.Path.GetTempPath() method.

Thanks again.

Normally all "users" should be able to create folders/files under the root,
which begs the question - are you *sure* you are getting an "Access Denied"
exception when trying to create a folder/file under the root ("C:\"), what
makes you so sure about it?
Don't run a Service as "Administrator", set your service to run in the
"Local Service" account, try to create a folder and a file, this should
work. If it doesn't check the security settings on the root.

Willy.

Willy.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.