Hi there,
I am writing a webservice and am wanting to use Server.MapPath to get
the path to some files on the server that is hosting the webservice. I
am using VB.NET atm, but am learning C#, so either example will be
fine. I have searched all over the newsgroups and forums to get an
example and have found many, but am unable to get any working. I have
got the webservice working, without the call to MapPath. But when I
try a simple example as follows with a call to MapPath it fails with
the error: "Object reference not set to an instance of an object.". I
understand what he error message is saying but don't know how to link
it to the instance, as none of the examples I have seen seem to do
this.
Any help or direction would be much appreciated, thank you for your
time,
Scott.
Here is the code I am using:
Imports System
Imports System.IO
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.WebService
Imports System.Xml.Serialization
Public Class UploadFile
<WebMethod> Public Function Upload(ByVal FlName As String) As String
Try
Dim strFilePath As String
strFilePath = HttpContext.Current.Server.MapPath("/" & FlName)
Return strFilePath
Catch ex As Exception
Return ex.Message
End Try
End Function
End Class