asp.net - Cant open a closed file -


i using code below try , open pdf file , getting error cannot open closed file? not sure missing here.

    dim filename string     dim folderlocation string = nothing     dim fileformat string = "application/pdf"     dim tfilenamearray array = nothing     dim tfilename string = nothing      filename = "\\server\files\45144584.pdf"      dim fs new filestream(filename, filemode.open, fileaccess.read)     using (fs)      end using     dim data() byte = new byte(fs.length) {}     dim br binaryreader = new binaryreader(fs)     br.read(data, 0, data.length)     br.close()     response.clear()     response.contenttype = fileformat     response.appendheader("content-disposition", "attachment; filename=" & tfilename.split("\")(tfilename.split("\").length - 1))     response.bufferoutput = true     response.binarywrite(data)     response.end() 

you need have code references fs inside of using, otherwise attempting access object has been disposed. same thing binaryreader, since implements idisposable:

dim data() byte using fs new filestream(filename, filemode.open, fileaccess.read)     data = new byte(fs.length) {}     using br new binaryreader(fs)         br.read(data, 0, data.length)     end using end using ... 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -