dcsimg
Results 1 to 10 of 10

Thread: [RESOLVED] Permission Denied in File system object

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2008
    Location
    India, Kerala, Calicut
    Posts
    242

    Resolved [RESOLVED] Permission Denied in File system object

    i am trying to write a file in the following way but its showing access denied error

    Code:
    '    tmp = App.Path & "\" & DoctorRs("CF_DOCTORCODE") & "\" & "Sign.jpg"
    '    Open App.Path & "\" & DoctorRs("CF_DOCTORCODE") & "\" & DoctorRs("CF_DOCTORCODE") & ".txt" For Output As #1
    '    Print #1, tmp
    '    Close #1
    Thanks in advance

  2. #2
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Permission Denied in File system object

    First off, I don't see any reference to the FileSystem Object - this looks like native file handling.

    I suspect that Windows is blocking writing to App.Path or the sub directory represented by "DoctorRs("CF_DOCTORCODE")" doesn't exist or is read only. Opening a file does not automatically create a directory if it doesn't exist.

    Also, you're assuming that File #1 is available to be used. You should use the FreeFile Function to let the system allocate a free file number
    Code:
    Dim intFile As Integer
    intFile = FreeFile()
    Open "<your full path to the file>" For Output As intFile
    Print #intFile, tmp
    Close intFile
    Last edited by Doogle; Apr 6th, 2012 at 12:59 AM.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2008
    Location
    India, Kerala, Calicut
    Posts
    242

    Re: Permission Denied in File system object

    i have declared this
    Code:
        Dim fs As New Scripting.FileSystemObject
        Set fs = New Scripting.FileSystemObject
    bt even after setting Free file.. its showing the same error

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,377

    Re: Permission Denied in File system object

    what is the content of DoctorRs("CF_DOCTORCODE") when the code runs
    does a folder of this name exist below app.path?
    you do not need filesystem object for the code as you have posted
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Oct 2008
    Location
    India, Kerala, Calicut
    Posts
    242

    Re: Permission Denied in File system object

    this is the code

    Code:
        Dim objFile As TextStream
        Dim tmp As String    
        Dim intFile As Integer
        Dim fs As New Scripting.FileSystemObject
        Set fs = New Scripting.FileSystemObject
        
        If Not fs.FolderExists(App.Path & "\" & DoctorRs("CF_DOCTORCODE")) Then
            fs.CreateFolder App.Path & "\" & DoctorRs("CF_DOCTORCODE")
        Else
            fs.DeleteFolder App.Path & "\" & DoctorRs("CF_DOCTORCODE")
            fs.CreateFolder App.Path & "\" & DoctorRs("CF_DOCTORCODE")
        End If
        
        fs.CopyFile txtSign.Text, App.Path & "\" & DoctorRs("CF_DOCTORCODE") & "\" & "Sign.jpg"
        Set fs = Nothing
        
        intFile = FreeFile()
        tmp = App.Path & "\" & DoctorRs("CF_DOCTORCODE") & "\" & "Sign.jpg"
        Open App.Path & "\" & DoctorRs("CF_DOCTORCODE") & "\" & DoctorRs("CF_DOCTORCODE") & ".txt" For Output As intFile
        Print #intFile, tmp
        Close intFile
    in CF_DOCTORCODE its a number is coming.

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,024

    Re: Permission Denied in File system object

    The most likely problem is something that Doogle implied before, and is explained in the article Where should I store the files that my program uses/creates? from our Classic VB FAQs (in the FAQ forum)

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Oct 2008
    Location
    India, Kerala, Calicut
    Posts
    242

    Re: Permission Denied in File system object

    I have logged in as administrator only...

  8. #8
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,234

    Re: Permission Denied in File system object

    In post #5, what line is causing the error?

    If the line of code that errors refers to txtSign.Text, what is the value of txtSign.Text?

    Also, can you show us the string value returned by the following line of code, when the error occurs:
    Code:
    App.Path & "\" & DoctorRs("CF_DOCTORCODE")
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Oct 2008
    Location
    India, Kerala, Calicut
    Posts
    242

    Re: Permission Denied in File system object

    THe content of TxtSign.text is "J:\1\sign.jpg"
    and the value returned by CF_DOCTORCODE is 4

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Oct 2008
    Location
    India, Kerala, Calicut
    Posts
    242

    Re: Permission Denied in File system object

    Its resolved!


    i put

    Code:
    fs.CopyFile txtSign.Text, App.Path & "\" & DoctorRs("CF_DOCTORCODE") & "\" & "Sign.jpg"
    and it worked
    Thank u everyone

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width