J
J055
Hi
I have the following code. I upload an XML file using the FileUpload object,
store the stream in a session so the user gets the chance to confirm some
options then pass the stream from the Session to an XmlReader.
if (performImport == false)
{
Session["__xmlImportFile"] = fileUpload1.FileContent;
//... some other code
}
else
{
if (Session["__xmlImportFile"] != null)
{
Stream xmlFile = (Stream)Session["__xmlImportFile"];
xmlFile.Position = 0;
// ... pass xmlFile to XmlReader
}
Session.Remove("__xmlImportFile");
}
This works fine on the Visual Studio web server. When I transfer the code to
an IIS web server I can only get the code to work if the uploaded file is
80Kb or less. Anything over that and I get an ObjectDisposedException
(Cannot access a closed file.) The size in bytes of the stream from the
session appears to be correct before the XmlReader is called.
[ObjectDisposedException: Cannot access a closed file.]
System.IO.__Error.FileNotOpen() +56
System.IO.FileStream.Seek(Int64 offset, SeekOrigin origin) +1945963
System.Web.TempFile.GetBytes(Int32 offset, Int32 length, Byte[] buffer,
Int32 bufferOffset) +35
System.Web.HttpRawUploadedContent.CopyBytes(Int32 offset, Byte[] buffer,
Int32 bufferOffset, Int32 length) +112
System.Web.HttpInputStream.Read(Byte[] buffer, Int32 offset, Int32 count)
+47
System.Xml.XmlTextReaderImpl.InitStreamInput(Uri baseUri, String
baseUriStr, Stream stream, Byte[] bytes, Int32 byteCount, Encoding encoding)
+196
System.Xml.XmlTextReaderImpl..ctor(Stream stream, Byte[] bytes, Int32
byteCount, XmlReaderSettings settings, Uri baseUri, String baseUriStr,
XmlParserContext context, Boolean closeInput) +62
System.Xml.XmlReader.CreateReaderImpl(Stream input, XmlReaderSettings
settings, Uri baseUri, String baseUriStr, XmlParserContext inputContext,
Boolean closeInput) +68
System.Xml.XmlReader.Create(Stream input, XmlReaderSettings settings,
String baseUri) +37
System.Xml.XmlReader.Create(Stream input, XmlReaderSettings settings) +30
Can you tell me what is happening here and how I might resolve it?
Many thanks
Andrew
I have the following code. I upload an XML file using the FileUpload object,
store the stream in a session so the user gets the chance to confirm some
options then pass the stream from the Session to an XmlReader.
if (performImport == false)
{
Session["__xmlImportFile"] = fileUpload1.FileContent;
//... some other code
}
else
{
if (Session["__xmlImportFile"] != null)
{
Stream xmlFile = (Stream)Session["__xmlImportFile"];
xmlFile.Position = 0;
// ... pass xmlFile to XmlReader
}
Session.Remove("__xmlImportFile");
}
This works fine on the Visual Studio web server. When I transfer the code to
an IIS web server I can only get the code to work if the uploaded file is
80Kb or less. Anything over that and I get an ObjectDisposedException
(Cannot access a closed file.) The size in bytes of the stream from the
session appears to be correct before the XmlReader is called.
[ObjectDisposedException: Cannot access a closed file.]
System.IO.__Error.FileNotOpen() +56
System.IO.FileStream.Seek(Int64 offset, SeekOrigin origin) +1945963
System.Web.TempFile.GetBytes(Int32 offset, Int32 length, Byte[] buffer,
Int32 bufferOffset) +35
System.Web.HttpRawUploadedContent.CopyBytes(Int32 offset, Byte[] buffer,
Int32 bufferOffset, Int32 length) +112
System.Web.HttpInputStream.Read(Byte[] buffer, Int32 offset, Int32 count)
+47
System.Xml.XmlTextReaderImpl.InitStreamInput(Uri baseUri, String
baseUriStr, Stream stream, Byte[] bytes, Int32 byteCount, Encoding encoding)
+196
System.Xml.XmlTextReaderImpl..ctor(Stream stream, Byte[] bytes, Int32
byteCount, XmlReaderSettings settings, Uri baseUri, String baseUriStr,
XmlParserContext context, Boolean closeInput) +62
System.Xml.XmlReader.CreateReaderImpl(Stream input, XmlReaderSettings
settings, Uri baseUri, String baseUriStr, XmlParserContext inputContext,
Boolean closeInput) +68
System.Xml.XmlReader.Create(Stream input, XmlReaderSettings settings,
String baseUri) +37
System.Xml.XmlReader.Create(Stream input, XmlReaderSettings settings) +30
Can you tell me what is happening here and how I might resolve it?
Many thanks
Andrew