|
-
May 4th, 2008, 11:03 PM
#1
Thread Starter
Frenzied Member
UnauthorizedAccessException
I can copy the folder to a USB drive without any problems
Code:
My.Computer.FileSystem.CopyDirectory(sourceFolder, destination & Me.TextBox1.Text & "StickFrameExpress\StickFrameExpress", Microsoft.VisualBasic.FileIO.UIOption.AllDialogs, FileIO.UICancelOption.ThrowException)
but if i try to zip the folder so i can upload to my ftp site i am getting a access denied error message.
Code:
System.UnauthorizedAccessException was unhandled
Message="Access to the path 'C:\Documents and Settings\toe\My Documents\Visual Studio 2005\Projects\StickFrameExpress' is denied."
Source="mscorlib"
StackTrace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at Microsoft.VisualBasic.FileIO.FileSystem.WriteAllBytes(String file, Byte[] data, Boolean append)
at Microsoft.VisualBasic.MyServices.FileSystemProxy.WriteAllBytes(String file, Byte[] data, Boolean append)
at AutoBackup.Form1.btnBackup_Click(Object sender, EventArgs e) in C:\Documents and Settings\toe\My Documents\Visual Studio 2005\Projects\AutoBackup\AutoBackup\Form1.vb:line 89
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at AutoBackup.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
When i check the folder attributes they are set to read only so i took the tick out and applied, all the attributes changed according to the notification but if i close the folder property window then open it again the folder attribute read only is ticked?
zip code
Code:
'get folder to zip
Dim srcfolderString As String = Me.txtSourceFolder.Text
Dim dstfolderString As String = "C:\Documents and Settings\toe\My Documents\Visual Studio 2005\Projects\StickFrameExpress"
'create empty zip file
Dim fileContents() As Byte = {80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
My.Computer.FileSystem.WriteAllBytes(dstfolderString, fileContents, False)
Dim objShell As New Shell32.ShellClass
Dim objFolderSrc As Shell32.Folder
Dim objFolderDst As Shell32.Folder
Dim objFolderItems As Shell32.FolderItems
objFolderSrc = objShell.NameSpace(srcfolderString)
objFolderDst = objShell.NameSpace(dstfolderString)
objFolderItems = objFolderSrc.Items
objFolderDst.CopyHere(objFolderItems, 20)
error highlites this line
Code:
My.Computer.FileSystem.WriteAllBytes(dstfolderString, fileContents, False)
I checked the error in the help:
Troubleshooting Exceptions: System.UnauthorizedAccessException
But alas i don't understand how to correct it.
regards
toe
-
Sep 23rd, 2015, 03:39 PM
#2
New Member
Re: UnauthorizedAccessException
This is WAY late - but I just saw it. Hope this will help someone else. Especially for Vista + (maybe XP - I didn't test)
Access to: C:\Documents and Settings\toe\My Documents\Visual Studio 2005\Projects\StickFrameExpress is denied (with the System.UnauthorizedAccessException because that path doesn't exist... even though it seems like it does.
My Documents is a construct of the "special folders" used to distinguish between the current user and others. You can verify this by bringing up a command prompt and navigating to the "StickFrameExpress" directory. My bet is that is does not match the path above. I would expect it to look more like: C:\Users\Toe\Documents\Visual Studio 2005\Projects\StickFrameExpress.
You can retrieve the right path for the current user's documents folder by:
Code:
My.Computer.FileSystem.SpecialDirectories.MyDocuments.ToString
Then just append the rest of the path: \Visual Studio 2005\Projects\StickFrameExpress
This exception happens all the time when trying to iterate through a directory structure - especially when using FileSystem.GetFiles and .GetDirectories - particularly when trying to use the SearchOption.SearchAllSubDirectories because VB will revert back to the My Documents (path that doesn't exist) in mid stream when it switches to parse a subdirectory.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|