Click here to Skip to main content
6,822,123 members and growing! (17,451 online)
Email Password   helpLost your password?
Desktop Development » Files and Folders » Utilities     Beginner License: The GNU Lesser General Public License

FileTrack: Co-Editing Files without Tears

By Gabriyel

A nifty tool to help people track changes in files in real-time
VB, Windows, .NET, Dev
Posted:19 Jun 2009
Views:3,774
Bookmarked:15 times
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
3 votes for this article.
Popularity: 2.11 Rating: 4.43 out of 5

1

2

3
1 vote, 33.3%
4
2 votes, 66.7%
5

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

About the Author

Gabriyel


Member

Occupation: Web Developer
Location: Singapore Singapore

Other popular Files and Folders articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 2 of 2 (Total in Forum: 2) (Refresh)FirstPrevNext
GeneralTracking files that are copied out of PC Pinmembertslu17:58 22 Jun '09  
GeneralRe: Tracking files that are copied out of PC PinmemberGabriyel18:05 22 Jun '09  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

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

PermaLink | Privacy | Terms of Use
Last Updated: 19 Jun 2009
Editor: Deeksha Shenoy
Copyright 2009 by Gabriyel
Everything else Copyright © CodeProject, 1999-2010
Web21 | Advertise on the Code Project