Where to place class file

R

Reggie

Hi and TIA! I have a class file located in my root directory with all me
web pages. I call/use the class and it works fine. I have no imports
statements aspx or codebehind. My question is why? I thought the class file
had to be compiled and placed in the bin directory or added to the
App_Code(as a class file) folder. I don't have it in either it's simply in
the root. Now When I compile it and place the dll in the bin and remove the
class file from the root it doesn't work until I also manually add a
reference to it in References. This brings me to another question. I read
that when you place it in the bin directory a reference is automatically
added. That doesn't happen for me. I have to manually add the reference.
And one more question(for now). You are supposed to be able to right click
the project select add/add aspnet folder/App_Code. When I do this the
App_Code file is in the list of options. I can obviously manually add the
folder, but thought this was odd. Thanks for any insight.
 
R

Reggie

Thanks Patrice. My bad. I miss-interpreted what was said here
http://msdn.microsoft.com/en-us/library/t990ks23(VS.80).aspx. It said you
can place the compiled assembly in the bin folder, and other code anywhere
in the Web application (such as code for pages) automatically references it.
That being said, when I compile the component and add it to the bin directy
and build the project it bombs out until I manually add the reference. At
the site above it doesn't mention that you have to add the reference. Is it
because I use it in my web page (aspx) file. It's basically a panel control
that I place things in such a gridviews that I want to export. I got this
somewhere on the web Can't remeber exactly where. The code is below. The
only reason I ask, is because I build the assemblies remotely, then ftp them
to the server to the bin folder, but I don't have access to perform the
reference manually unless there's some way to programatically do it. I will
do some research on the difference between the Web Site app proj and the Web
App Proj. Wasn't aware there is 2 different models. My app was originally
built in VS2003 now using VS2005 and as you made me aware I guess mine is a
Web App Proj. How did you know that? Is there a way to tell? Thanks again
for all your help/time!

Imports System.ComponentModel
Imports System.Web.UI

<ToolboxData("<{0}:ExportPanel runat=server>" _
+ "</{0}:ExportPanel>")> _
Public Class ExportPanel
Inherits System.Web.UI.WebControls.Panel

#Region " Public Properties "
'Contains the list of supported export applications
Public Enum AppType
HTML
Word
Excel
PowerPoint
WordPerfect
End Enum

'Manage the requested export type
Private m_ExportType As AppType
<Bindable(True), Category("Behavior"), DefaultValue("Excel")> _
Public Property ExportType() As AppType
Get
Return m_ExportType
End Get

Set(ByVal Value As AppType)
m_ExportType = Value
End Set
End Property

'Filename property
Dim m_FileName As String = "File1"
<Bindable(True), Category("Appearance"), _
DefaultValue("File1")> _
Public Property FileName() As String
Get
Return m_FileName
End Get

Set(ByVal Value As String)
m_FileName = Value
End Set
End Property

'Open the application externally or host in the browser?
Private m_OpenInBrowser As Boolean = True
<Bindable(True), Category("Behavior"), DefaultValue("True")> _
Public Property OpenInBrowser() As Boolean
Get
If ExportType = AppType.WordPerfect Then
'WordPerfect(can) 't be hosted inside IE
Return False
Else
If ExportType = AppType.HTML Then
'HTML will always be displayed
'on the current page.
Return True
Else
Return m_OpenInBrowser
End If
End If
End Get

Set(ByVal Value As Boolean)
m_OpenInBrowser = Value
End Set
End Property
#End Region

Protected Overrides Sub Render(ByVal output As _
System.Web.UI.HtmlTextWriter)
If ExportType = AppType.HTML Then
MyBase.Render(output)
Else
'get rid of all the junk that's been
'rendered to the page so far
Page.Response.Clear()

'start a very simple html document
Page.Response.Write("<html><head></head><body>")

'determine whether to open the document inside
'the browser or to an launch external app
Dim OpenType As String = "inline"
If OpenInBrowser = False Then OpenType = "attachment"

'determine the content type and file extension
Dim FileExtension As String = ""
With Page.Response
Select Case ExportType
Case AppType.Excel
.ContentType = "application/ms-excel"
FileExtension = ".xls"
Case AppType.Word
.ContentType = "application/ms-word"
FileExtension = ".doc"
Case AppType.PowerPoint
.ContentType = "application/ms-powerpoint"
FileExtension = ".ppt"
Case AppType.WordPerfect
.ContentType = "application/wordperfect9"
FileExtension = ".wpd"
End Select
End With

'build full filename with extension (if necessary)
Dim FullFileName As String = FileName.Trim().ToLower
If Not FullFileName.EndsWith(FileExtension) Then
FullFileName += FileExtension
End If

'Output the HTML header
Page.Response.AddHeader("Content-Disposition", _
OpenType + ";filename=" + FullFileName)

'Output the contents of the panel
MyBase.RenderChildren(output)

'End the HTML document
Page.Response.Write("</body></html>")
Page.Response.End()
End If
End Sub

End Class



Reggie
Patrice said:
It depends on the project model you are using. With the model you are
using (Web Application Project) all the code is compiled into a single DLL
so you have nothing special to do.

Humm... not sure but never heard about this automatic reference thing. IMO
it would be rather the other way round i.e. when you make a reference and
copy local is true then the DLL is copied into the bin directory. So this
is placed in bin because it is referenced (and not referenced because
placed in bin).

App_Code is for Web Site application project (compiled into multiple DLLs
so general code has to be placed at this particular location).


See :
http://msdn.microsoft.com/en-us/library/aa730880(VS.80).aspx for a
detailed discussion.
 

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

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top