PDA

Click to See Complete Forum and Search --> : FSO.MoveFile Permission Denied


pgrimes
Aug 1st, 2002, 03:05 PM
I am trying to use VB .NET and the "Scripting.FileSystemObject" to move around some files. I have done this plenty of times before in asp w/ vbscript. My problem seems to be a permissions issue according to the error message.

Here is the message I get:

Security Exception
Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

Exception Details: System.Security.SecurityException: Exception from HRESULT: 0x800A0046 (CTL_E_PERMISSIONDENIED).

Source Error:


Line 269: If Not objFSO.FileExists(uploadMovePath & "\" & moveFileName) Then
Line 270: objFSO.MoveFile(cptFilePath, uploadMovePath & moveFileName)
Line 271:



Source File: G:\WebServer\cpthandler\processUploads\WebForm1.aspx.vb Line: 270

Stack Trace:


[SecurityException: Exception from HRESULT: 0x800A0046 (CTL_E_PERMISSIONDENIED).]
Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateCall(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack, Boolean IgnoreReturn)
Microsoft.VisualBasic.CompilerServices.LateBinding.LateCall(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack)
processUploads.processUpload.Page_Load(Object sender, EventArgs e) in G:\WebServer\cpthandler\processUploads\WebForm1.aspx.vb:270
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
System.Web.UI.Page.ProcessRequest()
System.Web.UI.Page.ProcessRequest(HttpContext context)
System.Web.CallHandlerExecutionStep.Execute()
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)


I have given modify and delete permissions to IUSR_machine, IWAM_machine, ASPNET, and at one point even the EVERYONE account, but I keep getting the same security message. I have also changed the UserName to System (password=AutoGenerate) in the machine.config file. At one point, just to test it, I even set myself (an administrator account) as the default web guest account... I still got the security error. I am able to copy files without a problem, but I can't move or delete files. Is it possible this message could be generated due to a problem other than security? There is a possibility that I'm setting the perimssions wrong... I right click on the folder that the files are moved around in, click security tab, give appropriate users modify permissions, then I click advanced, then click view/edit, and check the delete box. I also make sure that it says apply to: "this folder, subfolders and files".

I have triple checked that the paths are corresponding to eachother correctly when I try to move the file. Here are the paths:

Move From:
G:\WebServer\cpthandler\SVGgraph\CPT Archive\temp\02-248.CPD

Move To:
G:\WebServer\cpthandler\SVGgraph\CPT Archive\2002 CPT Data\07-195901\02-248.CPD

If you want me to post my code, let me know.


Thanks for any help.

Paul

pgrimes
Aug 1st, 2002, 04:38 PM
ps.

I just ran some a coulpe of asp 3.0 pages, one creates a file and one deletes a file. They both work, and they create and delete the file in the same friggin' directory where the .NET is trying to move the file.

I noticed this in the error message from .NET:

"... or change the application's trust level in the configuration file"

I have checked in the web.config file, but didn't really see anything in there to change. As I mentioned earlier, the machine.config file is using the System account, so, it has priv's there.

:(:(:(:(:(:( stuck

Matt02
Aug 1st, 2002, 05:32 PM
I think I know what this is, but not how to fix it. If you go to your control panel and open the Administrative Tools, in there you will find the Microsoft .NET Configuration program. You can use this to set the access permissions of your .net programs, but I'm not sure exactly what setting you need to modify.

pgrimes
Aug 1st, 2002, 06:28 PM
hmm...

The "Microsoft .NET Framework Configuration" (mscorcfg.msc) doesn't do anything when I double click it.

The "Microsoft .NET Framework Wizards" (ConfigWizards.exe), gives the following options:
1.) Adjust .NET Security - this didn't help, I gave all options full
trust, and still got my @#!*@$@#$@*&^ error
2.) Trust an Assembly - this let's me choose from every dll and
exe file on my computer. I can choose one and "trust the
managed assembly". Could this be what I need to do?
Which dll would I trust? They all seem so friendly, I just can't
choose :).

Thanks for the reply...

please keep any suggestions comin'


Paul

DevGrp
Aug 2nd, 2002, 09:23 AM
You have to give the calling program the right security clearance for moving and deleting. Remember the framework is assuming that everone that will be using the program wont have admin right so you have to do this explicitly.

You should have seen this from the exception that was thrown. You need to check out thee System.Security namespace. That will solve all our problems.

Dev

pgrimes
Aug 2nd, 2002, 12:39 PM
You have to give the calling program the right security clearance for moving and deleting. Remember the framework is assuming that everone that will be using the program wont have admin right so you have to do this explicitly.

You should have seen this from the exception that was thrown. You need to check out thee System.Security namespace. That will solve all our problems.
I Already did that.


But... turns out this wasn't even a permissions problem...

I changed the code where the file is moved from this:

objFSO.MoveFile(cptFilePath, uploadMovePath & moveFileName)

to this:

File.Move(cptFilePath, uploadMovePath & moveFileName)

This gave a different error message. Instead of a permission denied error, it told me what I needed to here. Cannot move "the file" because "the file" is being used by another process.

That tipped me off real quick, and I realized that I had a streamReader open on the file I was trying to move. So, I closed the streamReader before the file gets moved and it works.

*DOH*:rolleyes:

Anyway, works like a charm now. Thanks for your help... sorry I wasted your time by being a blind moron. :)