Creating a class library

I am creating a class library that will encapsulate all of the database
access code. Within the class library, I want the code to establish the
Server.MapPath of a database file for use in a connection string.
Currently, Visual Studio.NET gives me an error on the Server.MapPath code.

When i compile i get the following message

Name "Server" is not declared.

What namespace should import into the class library so VS.NET will
understand the Server.MapPath code. I have tried a bunch, but none seems to
work.

The Names spaces used in this class library

Imports System
Imports System.Data.SqlClient
Imports System.Web.HttpContext
Imports System.Web.Mail
Imports System.Text
Imports System.IO
Imports eBusiness
Imports Microsoft.VisualBasic
Imports System.Security
Imports System.Security.Permissions
Imports System.Collections
Imports System.Web
Imports System.Collections.Specialized
Imports System.Web.HttpContext.current





Here is the Code>>>>>

Public Function UploadAttachments(ByVal lAttachmentID As Long, ByVal lAdvertisementID As Long, ByVal lUser_ID As Long, ByVal IsEditMode As Long)
        Dim directorySeparatorChar As Char = Path.DirectorySeparatorChar
        'loop through the files uploaded
        Dim colFiles As System.Web.HttpFileCollection = System.Web.HttpContext.Current.Request.Files

        'Message to the user
        Dim strMessage As New System.Text.StringBuilder("Files Uploaded:<br><br>")
        Dim intFileCntr As System.Int32
        Dim Attachment_Type_ID As Long

        Dim oUploadPath As NameValueCollection
        Dim sPath As String
        'Get Upload Path from WebConfig file

        oUploadPath = CType(HttpContext.Current.GetConfig("appSettings"), NameValueCollection)
        sPath = oUploadPath("app_upload_path").ToString()

        Try

            For intFileCntr = 0 To colFiles.Count - 1
                Dim objCurrentFile As System.Web.HttpPostedFile = colFiles(intFileCntr)
                Dim strCurrentFileName, strCurrentFileExtension As System.String
                strCurrentFileName = System.IO.Path.GetFileName(objCurrentFile.FileName)

                If strCurrentFileName <> "" Then
                    strCurrentFileExtension = System.IO.Path.GetExtension(strCurrentFileName)
                    If strCurrentFileExtension <> "" Then
                        If Not IsEditMode = 0 Then
                            Call InsertAttachments(lAdvertisementID, enumInspectionTypeID.Advertisement, strCurrentFileName, lUser_ID)

                        Else
                            Call UpdateAttachments(lAttachmentID, lAdvertisementID, enumInspectionTypeID.Advertisement, strCurrentFileName, lUser_ID)
                        End If
                        Try
                            Dim root As String = System.Web.UI.Server.MapPath("Attachments\" & "\" & lAdvertisementID)
                            Dim postedFile = objCurrentFile
                            Dim filename = Path.GetFileName(postedFile.FileName)

                            Dim contentType As String = postedFile.ContentType
                            Dim contentLength As Integer = postedFile.ContentLength
                            If Not Directory.Exists(root) Then
                                Directory.CreateDirectory(root)
                            End If
                            postedFile.SaveAs(root & directorySeparatorChar.ToString() & filename)

                        Catch ex As Exception

                            Throw New Exception("Error Creating Directory: " & ex.Message)

                        End Try
                    End If
                End If

            Next
            Return True
        Catch Ex As System.Exception
            Throw New Exception("Error Saving File : " & ex.Message)
        End Try

    End Function
<<<<<<<End of Code>>>>>>

Thanks in advance!
LVL 1
CIT_DEVAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ecc204Commented:
Your existing code is not referring to an instance of Server.   You need to call

HttpContext.Current.Server.MapPath("xxxx.xx")

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DevastatedCommented:
Hi,

perhaps it my own lack of something but to me the line

Dim root As String = System.Web.UI.Server.MapPath("Attachments\" & "\" & lAdvertisementID)

makes little sense...

to use server.mapPath i would simply do the following...

Imports System.Data.OleDb

dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & server.mappath("northwind.mdb"))

it then maps a path relative to the location of the file you are calling it from.

Hope this helps.

CIT_DEVAuthor Commented:
The line should read
Dim root As String = Server.MapPath("Attachments\" & "\" & lAdvertisementID)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.