473,508 Members | 2,382 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unable to open attachment

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
closed.]

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
D:\ITRS_Testing\ITRS\EnquiryResult.aspx:28
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEven t(String eventArgument)
+107

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
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102

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

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
server.....
objStream.Open("URL=http://Teklang1/ITRS_Testing/ITRS/Attachments/"
& Trim(txtAttachment.Text))
'objStream.Open("//Teklang1/ITRS_Testing/ITRS/Attachments/" &
Trim(txtAttachment.Text))

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

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

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

Regards,
SB
Feb 20 '06 #1
0 2334

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1932
by: bmcelhany | last post by:
I have a windows service that monitors a directory for newly created files. When one is found, an e-mail is generated and the new file is added as an attachment. In order to avoid trying to attach...
0
1845
by: Steve Chatham | last post by:
I am stuck on this. It ought to be a simple reason as to why this is problematic, in that it works on smaller groups of data (say under 40 records), but doesn't on larger groups of records (40+)....
3
2413
by: Chris Thunell | last post by:
I am using the following code to send email out in a vb.net web program through an exchange 2003 server. My web server is on a separate server. When i try to send email inside the office, it works...
6
3521
by: Seok Bee | last post by:
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)....
0
12002
by: bazzer | last post by:
hey, im trying to access a microsoft access database from an ASP.NET web application in visual basic 2003.NET. i get the following error when i try running it: Server Error in...
0
1635
by: bananularstyle | last post by:
Hi everyone, This is an issue I have been picking away at for the past two weeks and am running short of ideas. :-\ I am writing an ASP page that allows a user to open/save a tif image stored on...
1
1808
by: sathvinder | last post by:
I just got an email with a 8mg attachment in pdf format. It locked up my computer. I used to be able to open large size attachment without any difficulty. If I even click on the email it will lock...
1
1438
by: =?Utf-8?B?RGF2aWQ=?= | last post by:
I am using vista with microsoft mail and microsoft works. When I send a mail with an attachment, the recipient opens them and they are empty. If I send the same mail and atachment to myself, it...
0
1715
by: sandeep98811 | last post by:
I am getting following weird issue, "When forwarding an email with an open attachment the user warned twice that an attachment is open". I am catching Forward event of mail item in function...
0
7115
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7321
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7036
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5624
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5047
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1547
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
414
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.