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.Serv ices
Imports System.Web.Serv ices.WebService
Imports System.Xml.Seri alization
Public Class UploadFile
<WebMethod> Public Function Upload(ByVal FlName As String) As String
Try
Dim strFilePath As String
strFilePath = HttpContext.Cur rent.Server.Map Path("/" & FlName)
Return strFilePath
Catch ex As Exception
Return ex.Message
End Try
End Function
End Class 2 23954
Scott wrote: 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.
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.Map Path("~");
}
</codeSnippet>
HTH,
Drew
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.
Drew Marsh <dr****@hotmail .no.spamming.co m> wrote in message news:<uh******* *******@tk2msft ngp13.phx.gbl>. .. Scott wrote:
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.
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.Map Path("~"); } </codeSnippet>
HTH, Drew This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: John Rebbeck |
last post by:
I've got the directory f:\Company\Product set as web shared so it's got a
virtual directory in the default web site on my test server's IIS. If I try
to use Server.MapPath in that site it returns a path within
c:\Inetpub\wwwroot rather than the real path.
Can anyone please tell me why this isn't working?
Regards,
John
|
by: canasdaq |
last post by:
Can anyone please help me. I was looking at the article "http://www.eggheadcafe.com/articles/20030603.asp". I am new to .net and know nothing in c#. I want to write a menu in asp.net. Can anyone please help me in converting this c# code to vb.net. I tried, but it is not giving the output. Here is the c# code
using System
using System.Collections
using System.ComponentModel
using System.Data
using System.Drawing
using System.Web
using...
|
by: Stephen |
last post by:
I have the following for a datagrid that inserts a row into an xml
file. It works great, but inserts the data to a new top-level node. I
don't know how to specifiy an existing node for the inserted item:
void DataGrid1_Update(Object Sender, DataGridCommandEventArgs e) {
try {
string stitle = (e.Item.Cells.FindControl("txttitle") as
TextBox).Text;
DataSet ds = new DataSet();
|
by: David Lozzi |
last post by:
Howdy,
I wrote a web service in .Net for my customer. My customer has another
vendor who now has to consume it but they are not using Visual Studio. Most
of their pages are jsp, and they said they need to consume this web service
using HTTP. The developer's IDE is Notepad. Yeah, weird I know.
How is this done? I guess if I can get it to run ASP, IDE independant, that
should make them happy. Any references you can point me to?
|
by: Lorenzo |
last post by:
Hello,
I have a web application with a virtual directory in it. With 'virtual
directory' i mean
a folder whose physical path is different from the physical path of the
application, but in which Web Sharing is active.
For example:
my application is in "C:\Inetpub\wwwroot\MyApp",
the Virtual folder is in "C:\VirtualFolder",
and IIS sees it as if it were in "C:\Inetpub\wwwroot\MyApp\VirtualFolder".
| |
by: vunet.us |
last post by:
How to use server.mappath() parent folder correctly:
Server.MapPath("../test.asp")
Thank you for the hint.
|
by: rn5a |
last post by:
Server.MapPath returns the physical file path that corresponds to the
specified virtual path whereas Request.MapPath maps the specified
virtual path to a physical path. Assuming that a file named Hello.aspx
resides in C:\Inetpub\wwwroot\MyFolder, the output of both
Response.Write(Server.MapPath("Hello.aspx"))
&
Response.Write(Request.MapPath("Hello.aspx"))
|
by: =?Utf-8?B?Um9nZXIgTWFydGlu?= |
last post by:
This is a follow-up to my post "Silverlight video doesn't work when file is
streamed from handler in ASP.net" at
http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.dotnet.framework.aspnet&mid=e9a38d03-83a8-41fc-8950-5ee60d2a18a5.
I have a web site under .NET 2.0 that renders videos using the Silverlight
media player. When I stream the video file (.wmv) to the browser via a
hard-coded link to the file,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |