Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / November 2004

Tip: Looking for answers? Try searching our database.

Using Server.MapPath in a Webservice?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Scott - 25 Nov 2004 02:05 GMT
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

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.