Access a file from a web page

  • Thread starter Thread starter news.bellatlantic.net
  • Start date Start date
N

news.bellatlantic.net

I created a class that populates a bunch of its properties from an XML file
on the file system. I'm planning on using the class on a bunch of sites all
working off the same XML file. In testing the idea, it looks like if two
users open a page that accesses the file one user will be locked out of the
file.

Is this a case for threading? How can I make sure that any number of people
can access the XML file at the same time?

Thanks for any ideas.
 
Hi,

Threading won't help you there since you seem to have locked the file.
Try reading the file without locking it, ie File.OpenRead or FileAccess
and FileShare set to Read

FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read,
FileShare.Read).
 
Thanks, I don't see a way to explicitly declare the file as "ReadOnly" using
the XmlTextReader, maybe it's the default? I'm starting to think maybe the
problem I had was not a file locking issue. This snippet is how I open the
file.
....
XmlTextReader xmlTextReader = new XmlTextReader(_appConfig);
xmlTextReader .Read();
while(xmlTextReader .Read()){
....

Thanks for your help!
 
I'm not familiar with XmlTextReader, but an option might be to read the
file into a MemoryStream and use that stream in the XmlTextReader
constructor.
 
Back
Top