UnauthorizedAccessException when running desktop application from shared folder

Posted by Atara on Stack Overflow See other posts from Stack Overflow or by Atara
Published on 2010-04-22T13:25:19Z Indexed on 2010/04/24 21:23 UTC
Read the original article Hit count: 234

I created a desktop application using VS 2008.

When I run it locally, all works well.

I shared my output folder (WITHOUT allowing network users to change my files) and ran my exe from another Vista computer on our intranet.

When running the shared exe, I receive "System.UnauthorizedAccessException" when trying to read a file.

How can I give permission to allow reading the file? Should I change the code? Should I grant permission to the application\folder on the Vista computer? how?

Notes:

  • I do not use ClickOnce. the application should be distributed using xcopy.

  • My application target framework is ".Net Framework 2.0"

  • On the Vista computer, "controlPanel | UninstallOrChangePrograms" it says it has "Microsoft .Net Framework 3.5 SP1"

  • I also tried to map the folder drive, but got the same errors, only now the fileName is "T:\my.ocx"

    ' ----------------------------------------------------------------------

    ' my code:

    Dim src As String = mcGlobals.cmcFiles.mcGetFileNameOcx()
    Dim ioStream As New System.IO.FileStream(src, IO.FileMode.Open)

    ' ----------------------------------------------------------------------

    Public Shared Function mcGetFileNameOcx() As String

    ' ----------------------------------------------------------------------

      Dim dirName As String = Application.StartupPath & "\"
      Dim sFiles() As String = System.IO.Directory.GetFiles(dirName, "*.ocx")
    
    
      Dim i As Integer
      For i = 0 To UBound(sFiles)
        Debug.WriteLine(System.IO.Path.GetFullPath(sFiles(i)))
        ' if found any - return the first:
        Return System.IO.Path.GetFullPath(sFiles(i))
      Next
      Return "" 
    
    
    End Function
    

    ' ----------------------------------------------------------------------

    ' The Exception I receive:

    System.UnauthorizedAccessException: Access to the path '\\computerName\sharedFolderName\my.ocx' is denied.
      at System.IO._Error(Int32 errorCode, String maybeFullPath)
      at System.IO.FileStream.Init(...)
      at System.IO.FileStream..ctor(...)
      at System.IO.FileStream..ctor(String path, FileMode mode)
    

    ' ----------------------------------------------------------------------

© Stack Overflow or respective owner

Related posts about unauthorizedaccessexcepti

Related posts about .NET