Tuesday, March 22, 2005

How to read a file that's in use by another process.

Recently I was needed to read context of some log file that's in use by another process when I trying to read from it.

It seems that there is no way to do it with System.IO.StreamReader. The stuff like:

using( System.IO.StreamReader logReader = new System.IO.StreamReader(logPath) )
System.String errorFileContext = updateErrorFileReader.ReadToEnd();

will cause System.IO.IOException with Message saying "The process cannot access the file ... because it is being used by another process."
My obvious guess was that System.IO.StreamReader doesn't have a constructor specifying the file sharing mode, so I switched to System.IO.FileStream:

using( System.IO.FileStream logReader = new System.IO.FileStream(
logFilePath, System.IO.FileMode.Open,
System.IO.FileAccess.Read, System.IO.FileShare.Read ) )
// In my case it always the case, o/w you can read file line-by-line
const int maxFileSize = 10*1024;
byte[] fileBytes = new byte[maxFileSize];

int amountOfBytes = updateErrorFileReader.Read(fileBytes, 0, maxFileSize);

System.Text.UTF7Encoding utf7 = new System.Text.UTF7Encoding();

System.String errorFileContext = utf7.GetString(fileBytes, 0, amountOfBytes);

MSDN documentation states that setting last parameter of System.IO.FileStream constructor to System.IO.FileShare.Read:

"Allows subsequent opening of the file for reading.
If this flag is not specified, any request to open the file
for reading (by this process or another process) will fail
until the file is closed. However, if this flag is specified
additional permissions might still be needed to access the file."

Well, that's was exactly what I was going to do and ... imagine my surprise when I got the same thing again:
System.IO.IOException with "The process cannot access the file ... because it is being used by another process.".

Solution came after playing a bit around. What you need to do - is to put last parameter to

It was quite surprising and took me some time to found it, since MSDN says that it "Allows subsequent opening of the file for reading or writing." while I was need reading only. Any way it just works...

Wednesday, March 09, 2005

Notepad++ : cool replacement for windows Notepad

Some time ago I started to use Notepad++ - freeware multi-document WYSIWYG editor with a lot of cool features (reg-ex find & replace, syntax highlighting for recognized languages, etc).
The good thing is that it has built-in files associations manager (Setting->Files Associations Manager), so you don't need to deal with replacement of standard Windows Notepad and associated problems as with Notepad2.

Sunday, March 06, 2005

Agile Project Management tools

Few days ago I was looking for some Agile PM tool to try.
After considering few options I've stopped on
XP StoryStudio . It seems that few other popular choices are TargetProcess and VersionOne .

While installation came smooth and usage is easy - here are few things that could be useful:

  • I succeeded to run it only with SQL running in Mixed Mode rather than Windows Authentication Mode (I'm using Desktop SQL engine).
    To install your SQL in Mixed Mode - use the following command line: setup SAPWD="MyPassword" SECURITYMODE=SQL .
  • If you want to check or change current SQL mode - here is how:
    "How to Determine or Change Your Authentication Mode -
    http://support.microsoft.com/?kbid=322336 "
  • If something gone wrong during the installation (one of post-installation tests failed) or you just want to reinstall it - you'll need manually eliminate XPStoryStudio link from the Default Web Page in IIS and delete C:\Program Files\Microsoft SQL Server\MSSQL\Data\StoryStudio.* files.

Does anyone have any suggestions/using experience regarding a PM tool you use?