flameworker
New Member
I have a windows form app in which users can open, create and save xml files. Files are typically saved to a network folder. I need to make sure a given file can only be opened by one user at a time. The xml file is loaded into a tree control and is saved frequently during a session. (almost any time a tree node is clicked)I'm opening the file like this:\[code\]FileStream fs = new FileStream(m_Filename, FileMode.Open);XmlReader reader = new XmlTextReader(fs);XmlSerializer deserializer = new XmlSerializer(typeof(BaseBoardTest));m_TestNodes = (BaseBoardTest)deserializer.Deserialize(reader);fs.Close();\[/code\]Saving like this:\[code\]TextWriter writer = new StreamWriter(filename);XmlSerializer serializer = new XmlSerializer(typeof(BaseBoardTest));serializer.Serialize(writer, m_TestNodes);writer.Close();\[/code\]I'd like to display a message stating which user/computer name has the file open if another user tries to open it or overwrite it via a save as.I am considering creating a lock file when a file is opened.Is there a better way to handle this?