[System.ObjectDisposedException] = {"Cannot access a closed file."

G

Guest

I am using the following code and i am getting the following error :-
"Cannot access a closed file." while reading the content of the InputStream.
Microsoft suggestes that one should not release the stream before accessing
the same.But here i am not releasing the stream.Suggestions/pointers will be
appreciated.

Thanks in advance
Ashish




try
{

foreach(HtmlInputFile hif in filesToImport)
{
// extract only the file name for the external file
string fileName = Path.GetFileName(hif.PostedFile.FileName);
// extract the content type (i.e. MIME type)
string mimeType = hif.PostedFile.ContentType;
// prepare to grab the content
byte[] content = new byte[hif.PostedFile.InputStream.Length];
// pull content out of the file
hif.PostedFile.InputStream.Read(content, 0, content.Length);
//Some more code...
.....
}
}
catch(Exception exp)
{

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top