Last post Mar 15, 2014 04:19 PM by rdavidson22
Mar 15, 2014 12:29 AM|rdavidson22|LINK
Ok so a little bit of background information before I ask my question. I have a desktop application that runs on my web server which writes xml files to an IIS directory every 5 seconds (The files are very small). So every 5 seconds each xml file is overwritten
with new, fresh data. I use these xml files to bind 2 gridviews and a datalist on an asp.net webpage via XmlDatasource controls. This page is kind of like a "live feed" for my users so I have placed a Timer control inside an AJAX UpdatePanel that refreshes
the gridviews and datalist every 5 seconds...I should also mention that I am setting the XMLDataSource.DataFile property on Page_Load according to the user's session value:
For example: FeedXDS.DataFile =
The problem is that I perodically get the following error:
The process cannot access the file 'C:\Webs\MySite\xml\7b7c972f-9545-4738-b5dc-b5ea00d21901.xml' because it is being used by another process.
I assume what is happening is the desktop application is trying to write the file while IIS is trying to read the file at the exact same time. How can I wrap the automatic databinding in a try catch statement?
Mar 15, 2014 05:41 AM|Mikesdotnetting|LINK
I think what I would do is the following in code behind (in pseudo-code):
see if a file exists
read XML file content
deserilaise it using LINQ to XML
delete the file
don't do anything
GridView.DataSource = cached data
Mar 15, 2014 12:12 PM|rdavidson22|LINK
So get rid of the XMLDataSources completely? Will this cause a performance hit and be slower using LINQ to query the xml as opposed to a XmlDataSource and XSLT to bind controls?
Mar 15, 2014 02:25 PM|Mikesdotnetting|LINK
So get rid of the XMLDataSources completely?
Yes. Define an entity to represent the XML and bind a collection of that to the GridView.
Will this cause a performance hit and be slower using LINQ to query the xml as opposed to a XmlDataSource and XSLT to bind controls?
Either way the XML structure is traversed and converted into a form that can be bound to the GridView. Linq might be slower or quicker. I don't know. It's not something that would worry me unduly.
Mar 15, 2014 04:19 PM|rdavidson22|LINK
Thank you for the suggestion. This seems to be working quite well so far!