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
Drew Marsh - 25 Nov 2004 03:56 GMT
> 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
[quoted text clipped - 7 lines]
> it to the instance, as none of the examples I have seen seem to do
> this.
I don't see any reason for it to not work, this works for me:
<codeSnippet language="C#">
[WebMethod]
public string MapPathTest()
{
return base.Server.MapPath("~");
}
</codeSnippet>
HTH,
Drew
Scott - 25 Nov 2004 06:50 GMT
I have worked it out. The error was actually being generated by the
calling page and it was just coincidence that I change the webservice
code the same time as I changed the calling page code.
Thanks anyway,
Scott.
> > 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
[quoted text clipped - 20 lines]
> HTH,
> Drew