By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,364 Members | 1,278 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,364 IT Pros & Developers. It's quick & easy.

Unable to open attachment

P: n/a
Dear Experts,

In my web application, I'm having a button to view an attachment. After I
retrieve the record from database (Ms. Access), I have a button to view the
attachment (if there is any). The button work fine when I run it at my local
machine. However, when I moved all the programs over to the server, I am
unable to view the attachment, although I have the file physically at the
server. The error message that I got is:

Server Error in '/ITRS_Testing' Application.

Operation is not allowed when the object is closed.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: Operation is
not allowed when the object is closed.

Source Error:

Line 26:
Line 27: ' This should be the full path and filename to save the
file on the client....
Line 28: objStream.SaveToFile(strFilename, 2) ' adSaveCreateOverWrite
Line 29: objStream.Close()
Line 30: objStream = Nothing

Source File: D:\ITRS_Testing\ITRS\EnquiryResult.aspx Line: 28

Stack Trace:

[COMException (0x800a0e78): Operation is not allowed when the object is

Microsoft.VisualBasic.CompilerServices.LateBinding .InternalLateCall(Object o,
Type objType, String name, Object[] args, String[] paramnames, Boolean[]
CopyBack, Boolean IgnoreReturn) +776
Microsoft.VisualBasic.CompilerServices.NewLateBind ing.LateCall(Object
Instance, Type Type, String MemberName, Object[] Arguments, String[]
ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack, Boolean
IgnoreReturn) +365640
ASP.itrs_enquiryresult_aspx.ViewDoc(Object Source, EventArgs E) in
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEven t(String eventArgument)

System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102

Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET

The code in my program is as follow:

Public Sub ViewDoc(ByVal Source As Object, ByVal E As EventArgs)
Dim strFilename As String
'================================================= ==============
' Example using ADODB Stream Object to load resource from server
' and deposit in specified directory on client, using client-side
' script
' Peter Bromberg
'================================================= ===============
' Don't need the TypeLib METADATA at the top if you specify the
constants by numeric value instead of by name

' Set up an ADO Stream ....
Dim objStream
objStream = CreateObject("ADODB.Stream")
objStream.Type = 1 ' adTypeBinary
' The following should be the absolute URL to the file on the
& Trim(txtAttachment.Text))
'objStream.Open("//Teklang1/ITRS_Testing/ITRS/Attachments/" &

Dim objFSO
objFSO = Server.CreateObject("Scripting.FileSystemObject")
strFilename = objFSO.getSpecialFolder(2).path & "\" &

' This should be the full path and filename to save the file on the
objStream.SaveToFile(strFilename, 2) ' adSaveCreateOverWrite
objStream = Nothing
' Now we'll "run" the file....
Dim AttachFile As System.IO.FileInfo = New
Response.AddHeader("Content-Disposition", "attachment; filename=" &
Response.AddHeader("Content-Length", AttachFile.Length.ToString())
Response.ContentType = "application/octet-stream"
End Sub

Please advise where is the mistake that I have made. Many thanks in advance.

Feb 20 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.