none
How to track the open document which is opened by another person RRS feed

  • Question

  • Hi,

    I have the hyperlink in table. when the user click on the link it suppose to open the document.

    The challenge of the task is, when one person open the document, then the other person should not open the document.

    It should say some alert saying "This person opening the document,pls. contact person to close the doc"

    How to track when person open the document then the other person should get alert message as soon as click the link.

    unless or untill user close the document, then the document link should be enable to open other person.

    How to handle this type of scenario...?

    Tuesday, March 5, 2019 10:08 AM

Answers

  • Hi,

    I test this code on my site and it's working well

    Private Function FileInUse(ByVal path As String) As Boolean
            Try
    
                Using fs As FileStream = New FileStream(path, FileMode.OpenOrCreate)
                End Using
    
                Return False
            Catch ex As IOException
                Return True
            End Try
        End Function
    
     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
            If FileInUse("F:\test.docx") = True Then
                MsgBox("file is open you can't use it")
                Exit Sub
            End If
            MsgBox("file is closed you can use it")
        End Sub
    
    
    

    You may make some modification to the output message to include the user name that is already logged in and use this file...... And  make a check box when this user open this file (check box true) and when close it (check box false).... After that you should make a table in your database with this (check box and user name) when any user try to open the file you can now know if the check box is true or false for a specific user and make an if statement or select case statement to decide if the user can open it or not .....

    Hope it helps


    Regards From Amr_Aly

    • Marked as answer by Gani tpt Tuesday, August 27, 2019 5:01 AM
    Saturday, March 9, 2019 7:28 AM

All replies

  • Hi,

    I think you need a way to check if the document has been opened.

      Public  Function IsFileInUse(ByVal fileName As String) As Boolean
            Dim inUse As Boolean = True
            Dim fs As FileStream = Nothing
    
            Try
                fs = New FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.None)
                inUse = False
            Catch
            Finally
                If fs IsNot Nothing Then fs.Close()
            End Try
    
            Return inUse
        End Function

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, March 6, 2019 1:46 AM
  • Hi,

    I test this code on my site and it's working well

    Private Function FileInUse(ByVal path As String) As Boolean
            Try
    
                Using fs As FileStream = New FileStream(path, FileMode.OpenOrCreate)
                End Using
    
                Return False
            Catch ex As IOException
                Return True
            End Try
        End Function
    
     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
            If FileInUse("F:\test.docx") = True Then
                MsgBox("file is open you can't use it")
                Exit Sub
            End If
            MsgBox("file is closed you can use it")
        End Sub
    
    
    

    You may make some modification to the output message to include the user name that is already logged in and use this file...... And  make a check box when this user open this file (check box true) and when close it (check box false).... After that you should make a table in your database with this (check box and user name) when any user try to open the file you can now know if the check box is true or false for a specific user and make an if statement or select case statement to decide if the user can open it or not .....

    Hope it helps


    Regards From Amr_Aly

    • Marked as answer by Gani tpt Tuesday, August 27, 2019 5:01 AM
    Saturday, March 9, 2019 7:28 AM