Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,
I am working on a Windows Application where i need to check a file exists in particular library with user crediantials.
Please suggest how to do it.

Note : .Net framework 1.1 (VS2003)
Posted

1 solution

I'm not exactly sure how this works in conjunction with user authorities to various libraries, but perhaps it will give you a place to start from. I use this to check if a library-file exists when connecting to an as400 system...our as400 is at V5R4, I'm not sure if it makes a difference as to what the error message would say. There is probably a better way, but this is what I've got and it seems to work for my purposes:

Private Function RunFileExists(ByVal instrLibAndFile As String, _
                      ByRef inconDb400 As IBM.Data.DB2.iSeries.iDB2Connection) As Boolean
        '***********************************************************************
        '   This method will:                                                   
        '       Accept a command and run the ExecuteScalar Function checking    
        '       for any errors                                                  
        '***********************************************************************
        Dim cmd As New IBM.Data.DB2.iSeries.iDB2Command
        cmd.CommandText = "SELECT * FROM " & instrLibAndFile & " WHERE 1=2"
        cmd.Connection = inconDb400

        Dim boolFileExists As Boolean = False


            If inconDb400.State <> ConnectionState.Open Then
                inconDb400.Open()
            End If
            Try
                Dim intI As Integer = cmd.ExecuteNonQuery
                boolFileExists = True
            Catch ex As IBM.Data.DB2.iSeries.iDB2SQLErrorException
                'To determine if the file exists or not, we are at the mercy of 
                'what is in the exception message    
                'which currently will display the text "FILE not found" when a
                'file is not found.                   
                If ex.Message.ToUpper.Contains("FILE NOT FOUND") Then
                    'File does not exist
                    boolFileExists = False
                    
                Else
                    'Some other error occurred, throw exception
                    Throw New System.Exception(ex.ToString)
                End If

            Catch ex As Exception
                'Some other error occurred, throw exception
                Throw New System.Exception(ex.ToString)
            Finally 'Always close connection
                If inconDb400.State <> ConnectionState.Closed Then
                    inconDb400.Close()
                End If
                cmd.Dispose()
            End Try


        Return boolFileExists
    End Function
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900