Results 1 to 4 of 4

Thread: picturebox and file permissions

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2003
    Location
    Toronto
    Posts
    8

    picturebox and file permissions

    i've been trying to figure this one out for 3 days now... with no luck. lets see if you guys can help me out

    the program i'm working on is kindof an image browser. it grabs some images from a dll, saves them locally, and lets you go through them one (each is refered to as a candidate image) by one comparing them with 'sister' images that exist in 6 remote directories, and allows you to update those directories as required. while you're going through the local drive, you have the option of editing the candidate with several droplets i've created in photoshop. here-in lies my puzzle.

    what happens is that the candidate image (mfSubject), which the user is being shown in a picturebox, is copied (mfGuineaPig) to the binary folder. the droplet is then invoked (system.diagnostic.process.start (myDroplet,myGuineaPigPath)), photoshop does it's thing, then i'm trying to save the copied file over the original candidate file and i jump right to my error handler (in the event... isn't in the method below).

    i've narrowed it down to one possibility: the picturebox is holding my file 'hostage'... while the program is running, i can't even delete the thing from explorer... and i can't get the image to 'release' it no matter what i've found as possible 'ransom'...

    make sense? anyway... here's the method... any ideas?
    ==========================================

    Private Sub callAPI(ByVal eProcess As cmeImgProcess, ByVal strImgPath As String)
    Dim objFSO As New Scripting.FileSystemObject()

    imgCandidate.Image = Nothing

    If objFSO.FileExists(strImgPath) Then
    mfSubject = objFSO.GetFile(strImgPath)
    objFSO.CopyFile(mfSubject.Path, getAppPath() & "\" & mfSubject.Name, True)
    mfGuineaPig = objFSO.GetFile(getAppPath() & "\" & mfSubject.Name)

    strImgPath = """" & mfGuineaPig.Path & """"

    Select Case eProcess
    Case cmeImgProcess.eipRegular
    System.Diagnostics.Process.Start("save140x200.exe", strImgPath)
    End Select

    If objFSO.FileExists(mfGuineaPig.Path) And objFSO.FileExists(mfSubject.Path) Then

    'mfSubject = Nothing

    ' MsgBox(mstrImportPath & "\" & mfGuineaPig.Name & vbCrLf & mfSubject.Path)
    objFSO.CopyFile(mfGuineaPig.Path, mstrImportPath & "\" & mfGuineaPig.Name, True)
    objFSO.DeleteFile(mfGuineaPig.Path)
    setImages() ' refreshes all pictureboxes
    Else
    MsgBox("File does not exist")
    End If

    End If

    If Not objFSO Is Nothing Then objFSO = Nothing

    End Sub ' activate ps Droplet

  2. #2

    Thread Starter
    New Member
    Join Date
    Jun 2003
    Location
    Toronto
    Posts
    8
    this is the error i get...

    An unhandled exception of type 'System.Security.SecurityException' occurred in browser_v2.1.exe

    Additional information: Exception from HRESULT: 0x800A0046 (CTL_E_PERMISSIONDENIED).

  3. #3
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    why are you using FSO in vb.net ? it shouldnt really be used in .net , the correct / safe / quick way is to use System.IO.File . eg:
    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Dim objFile As IO.File
    3.         Try
    4.             If objFile.Exists("C:\test.txt") Then
    5.                 objFile.Copy("C:\test.txt", "D:\test1234.txt")
    6.             Else
    7.                 MessageBox.Show("Oops the file doesnt exsist!")
    8.             End If
    9.         Catch ex As Exception
    10.             MessageBox.Show(ex.Message)
    11.         End Try
    12.     End Sub
    much easier than FSO and it does the job.
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  4. #4

    Thread Starter
    New Member
    Join Date
    Jun 2003
    Location
    Toronto
    Posts
    8
    i've switched up the code as you suggested... moved the problem code to it's own function to segregate it from 'happy' code

    =====
    Private Sub saveAPI(ByVal strGuineaPig As String, ByVal strSubject As String)
    Dim objFile As IO.File

    If objFile.Exists(strGuineaPig) And objFile.Exists(strSubject) Then

    'mfSubject = Nothing

    ' MsgBox(mstrImportPath & "\" & mfGuineaPig.Name & vbCrLf & mfSubject.Path)
    objFile.Delete(strSubject)
    objFile.Copy(strGuineaPig, strSubject)
    objFile.Delete(strGuineaPig)
    Else
    MsgBox("File does not exist")
    End If

    End Sub ' activate ps Droplet
    ====

    this is a lot cleaner (didn't know FSO was a no-no in .net... i'm the first in the office to get into it, so no one really knows the guidelines more than i do at this point... )

    still getting permission errors, though. basically says that it's being used by someone else (a little more honest than the ever-vague "permission denied" stuff from before)... hmmmmmmm.....

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