File is read only until my application is exited

[ Edited ]

I am in the process of writing a program to check and amend file properties for SE files. I have the following function to retrieve given properties from a solid edge file. The problem I have is that it seems running the function below creates a lock on the file I am querying until the application is closed.

e.g. I call  GetSolidEdgeFileProperties("C:\Part1.par","Custom","MyCustomProp") and get the value returned for property MyCustomProp, so in that respect the code below runs fine. The problem I have is that once I've made that call, the file will only open read-only until my program is closed (after which it will open just fine!).

I am trying to add functionality to allow the user to modify properties using my program but can't write the values back as the file is made read only once the initial  GetSolidEdgeFileProperties call is made.

 Public Function GetSolidEdgeFileProperties(ByVal Filename As String, ByVal PropertySet As String, ByVal PropertyName As String) As String        'Function to get file properties from a Solid Edge document.        Dim objPropertySets As New SolidEdgeFileProperties.PropertySets        Dim objProperties As SolidEdgeFileProperties.Properties        Dim objProperty As SolidEdgeFileProperties.Property        Dim objMyproperty As SolidEdgeFileProperties.Property        Dim propFound As Boolean = False


            objPropertySets.Open(Filename, True)            objProperties = objPropertySets.Item(PropertySet)

            'Check if the property exists in the file            For i = 0 To objProperties.Count - 1                objMyproperty = objProperties.Item(i)                If objMyproperty.Name = PropertyName Then                    propFound = True                    Exit For                End If            Next

            If propFound = False Then                'Property not found                Return ""            Else                'Property found                Return objMyproperty.Value            End If


        Catch ex As Exception            MsgBox(ex.Message)        Finally            If Not (objMyproperty Is Nothing) Then                Marshal.ReleaseComObject(objMyproperty)                objMyproperty = Nothing            End If            If Not (objProperty Is Nothing) Then                Marshal.ReleaseComObject(objProperty)                objProperty = Nothing            End If            If Not (objProperties Is Nothing) Then                Marshal.ReleaseComObject(objProperties)                objProperties = Nothing            End If            If Not (objPropertySets Is Nothing) Then                Marshal.ReleaseComObject(objPropertySets)                objPropertySets = Nothing            End If        End Try    End Function

I hope you can understand this issue, any help or advice is much appreciated.





Posted by: Alex Lush
Post date: 6/23/2011 4:00:11 AM


RE: File is read only until my application is exited

[ Edited ]


I added the lineGC.Collect()

as the last line inside the Finally section which seems to have fixed most of the problems but I'm still getting the odd (seemingly random) STG_E_SHAREVIOLATION errors.

Different files each time, not a specific file on every run, sometimes it works sometimes it doesn't!!

Any ideas??



Posted by: Alex Lush
Post date: 6/24/2011 3:17:55 AM