Unable to open file

G

Guest

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.NewLateBinding.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.RaisePostBackEvent(String eventArgument)
+107

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection 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
 
C

Cor Ligthert [MVP]

Seok,

Mostly are this kind of problems that the ASPNET user has not the proper
rights.

Be very careful with giving the ASPNET or other general user rights, if you
do that wrong you are able to open your complete server for the outer world.

I hope this helps,

Cor
 
G

Guest

Cor,

Can I create the ASPNET user in the webserver which is also the domain
controller of my company. It is running on Window 2000 sp4. Which means can I
create the user in the Active Directory?
 
G

Guest

I've checked from the Active Directory and the user ASPNET is not there?
Does that mean I need to install certain thing?
 
C

Cor Ligthert [MVP]

Seok,

Are you sure that IIS and the proper Net framework version are installed?

Cor
 
G

Guest

Yea, this is our webserver.
..NET Framework 2.0 is being installed. Now I'm installing .NET Framework 1.1
and the service pack
 

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