Currently I have a C# application that reads an XML file. But if this XML file is opened in word and then my application reads the same XML file, I get an IO Exception. All I need to do is read the file. Here is a small code snippet;
public Object Load()
{
try
{
using (FileStream fs = new FileStream(
filePath,
FileMode.Open,
FileAccess.Read,
FileShare.ReadWrite)) // Also tried, FileShare.Read and gets the same exception
{
return ((FooObject) new XmlSerializer(typeof(FooObject))
.Deserialize(fs)) as Object;
}
}
catch (Exception ex)
{
LogException(ex);
return null;
}
}