Click to See Complete Forum and Search --> : XML-XSL (File can't be accessed)


callavin
October 25th, 2006, 02:57 AM
I have one application which is transforming the XML based on the XSL.
In that Application I am first dumping the transformed content in a temp file and then I am reading that dumped content in the stream and showing in the browser.
But this application sometimes gives me error
" File cannot be accessed as it is being used by some process"

the solution seems to me like this:
I should not write the content in any file instead of it I should put in memory, but question is how?
other
If I am using the file as a temporary then how to avoid this exception?


Thanks!!

laasunde
October 25th, 2006, 04:09 AM
Do you close the temp file?

You could use filemon (http://www.sysinternals.com/Utilities/Filemon.html) to see what process is using the file.

Could you show us the code you are using.

callavin
October 25th, 2006, 04:37 AM
XPathDocument myXPathDocument = new XPathDocument(xmlfileName);
XslCompiledTransform myXslTransform = new XslCompiledTransform();
XmlTextWriter writer = new XmlTextWriter(tempFileName, null);
myXslTransform.Load(xslFileName);
myXslTransform.Transform(myXPathDocument,null, writer);
writer.Close();
stream = new StreamReader(tempFileName);
string toReturn = stream.ReadToEnd().ToString();

And this string I am showing in the browser.
The question is how to avoid this file operation?

callavin
October 25th, 2006, 05:09 AM
Closing the stream will make the application not to give the exception, but still the unnecessary file operation which is taking place can be reduced.
any idea about that??

laasunde
October 25th, 2006, 08:57 AM
Not sure if this is what you are looking for but have a look at MemoryStream (http://msdn2.microsoft.com/en-us/library/system.io.memorystream.aspx).