Click here to Skip to main content
12,694,121 members (35,411 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

15.7K views
381 downloads
17 bookmarked
Posted

FileTrack: Co-Editing Files without Tears

, 19 Jun 2009 LGPL3
Rate this:
Please Sign up or sign in to vote.
A nifty tool to help people track changes in files in real-time

Background

Not everyone in this world knows how to setup CVS or SVN to track changes in files. It would be horrendous if a non-technical person is required to install such a system everytime a file needs to be shared and co-edited in some way. The worst part of it is that in the real world, people do share files and co-edit them in many ways. The most common example is sharing Excel files for all the possible reasons (accounting, logistics, scheduling, etc.). Although Microsoft provides an automatic mechanism that notifies if a document is being modified at the same time if two persons try to edit it simultaneously, this only applies to Office documents.

So here lies the big problem - the pain of data corruption when people overwrite one another's files.

Solution

The inspiration to create this tool comes from the need to co-share and edit a special file format which is foreign to Microsoft Office. Microsoft provides a useful API for monitoring file system changes in .NET under System.IO.FileSystemWatcher class. There are assisted call-backs when the file referenced by an object from this class changes. The nice part of this is it works across LAN so in a private company network or even via VPN when someone is in different parts of the world, one can keep monitoring shared file changes.

// ...
// Imports System.IO
// ...
// Public Class Main
//    Dim fsw As FileSystemWatcher 	' You need to instantiate an object 
//				' from FileSystemWatcher class
//    Dim fw As StreamWriter
//	  ...
// ' These are the callback functions when the file changes
//    Private Sub File_Created(ByVal obj As Object, ByVal e As FileSystemEventArgs)
//        'fw.WriteLine(Now.ToShortDateString & " " 
//        '& Now.ToShortTimeString & " - " & e.FullPath & " - Created")
//    End Sub

//    Private Sub File_Deleted(ByVal obj As Object, ByVal e As FileSystemEventArgs)
//        'fw.WriteLine(Now.ToShortDateString & " " 
//        '& Now.ToShortTimeString & " - " & e.FullPath & " - Deleted")
//        MsgBox("Someone has deleted the file you are tracking! 
//	 		Please alert the Administrator immediately!")
//    End Sub

//    Private Sub File_Changed(ByVal obj As Object, ByVal e As FileSystemEventArgs)
//        'fw.WriteLine(Now.ToShortDateString & " " 
//	 '& Now.ToShortTimeString & " - " & e.FullPath & " - Deleted")
//        fsw.EnableRaisingEvents = False

//        'Dim objFileInfo As FileInfo = 
//	 'New FileInfo("\\expsrv01\FileServer\SCRUM\2008-SP01.xmn")
//        Dim objFileInfo As FileInfo = New FileInfo(OpenFileDialog1.FileName)
//        If objFileInfo.Exists = False Then
//            Return  ' Ignore the file open
//        End If

//        MsgBox("File has been changed. Please save your current work _
//		and close it before proceeding to reload the file.")

//        ' Load a new copy of the current file. 
//	 'This prevents the current copy from being destroyed accidentally.
//        Start(OpenFileDialog1.FileName)

//        Try
//            Dim bgImage As Bitmap = New Bitmap_
//		(GetEmbeddedResourceStream("FileTrack.red.jpg"))
//            Button4.BackgroundImage = bgImage
//        Catch ArgException As System.ArgumentException
//            MessageBox.Show(Me, "There was an error getting your resource. _
//		The resource name is most likely not correct.")
//        End Try

//        ' Re-enabling file monitoring
//        Invoke(Renew)
//    End Sub

Points of Interest

Instead of just a code snippet that works, this small application can run minimized in your icon tray. So it is non-obtrusive to your desktop or the way you work. And it alerts when something happens to the file you are tracking.

This tool does not help you to merge your file differences. When changes are tracked while you are editing it, you are responsible to keep your current copy of the file (in whichever format it is) and merge it yourself in the appropriate way with the existing version.

A NSIS installer script is provided for those who know how to setup and create an installer using the Nullsoft system. This would be more user-friendly instead of distributing a raw EXE which may not run sometimes if the associated files are missed out.

History

  • 19th June, 2009: Initial version

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)

Share

About the Author

Gabriyel
Singapore Singapore
No Biography provided

You may also be interested in...

Comments and Discussions

 
GeneralTracking files that are copied out of PC Pin
tslu22-Jun-09 17:58
membertslu22-Jun-09 17:58 
GeneralRe: Tracking files that are copied out of PC Pin
Gabriyel22-Jun-09 18:05
memberGabriyel22-Jun-09 18:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170118.1 | Last Updated 19 Jun 2009
Article Copyright 2009 by Gabriyel
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid