CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2000
    Location
    Germany, Franken
    Posts
    257

    Access Denied with FileStreamObject

    Hi,
    i have i little app which should copy one file from one folder to another. But if i call this app i got the error 70: Access Denied.
    Here's the code:

    set fso = CreateObject("Scripting.FileSystemObject")
    frmStep2.fso.copyfile App.Path & "\files\aDll.dll", frmStep2.txtDLL.Text




    Does anyone knows what could be wrong?

    thanks

    Akademos


  2. #2
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Access Denied with FileStreamObject

    If you are trying rto read a file into a textbox you are going about the wrong way. COpyFile is used to copy one file to another not to a control.
    The below sample will read a file into a testbox using File System Object.
    To test this code, start a new project, select standard.
    '
    Add a large textbox, making its Multiline Property = True.
    '
    Add a command button.
    '
    Go to Project/References and select Microsoft Scripting Runtime.
    '
    Paste this code into the general declarations section of the form
    '
    run the program.
    '
    Click the command button

    option Explicit

    private Sub Command1_Click()
    Dim FSO as new FileSystemObject
    Dim TS as TextStream
    Dim strBuff as string
    set TS = FSO.OpenTextFile("c:\Autoexec.bat", ForReading)
    Do Until TS.AtEndOfStream

    strBuff = TS.ReadLine
    Text1.Text = Text1.Text & strBuff

    Loop
    TS.Close
    set FSO = nothing

    End Sub




    John G

  3. #3
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Access Denied with FileStreamObject

    My guess is that the file you are trying to copy (the dll) is in use by another program. This result in the dll being locked exclusive, meaning that no other process can open the file, not even read only.

    The down side of the story is that you cannot do anything about this in code. You just have got to make sure the dll is not in use, one way or another.


    Other possibilities could be
    1) you do not have permissions to access the file
    2) you do not have permissions to write to the location specified
    3) the target file is in use, and therefore cannot be overwritten

    ...but I think these 3 last ones are unlikly

    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  4. #4
    Join Date
    Mar 2000
    Location
    Germany, Franken
    Posts
    257

    Re: Access Denied with FileStreamObject

    I found the error. I forgot to add the filename in the destination.

    I overread that (what a stupity)

    thanks anyway

    akademos


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured