473,398 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Web service - Access Local File

markmcgookin
648 Expert 512MB
Folks,

I have an ASP .Net web service that I am using for a product in work. But we need to make this a more "portable" for installation on other boxes. One of the requirements is to avoid a recompile when performing different installs. Thus we can't have any hard coded paths in the service.

So I have some code I wrote for another application that happily parses an xml file and stores a load of local variables based on it's content, which should be sufficient... however the service doesn't seem to run from the same place each time, from what I gather the code is kept in a .dll file which is moved to a temporary directory on the server when the service is started, and is random each time.

What I want to know is, is it possible for a web service to be aware of the file path that the web site it is running in in IIS allowing us to reference it no matter where it is installed (Like Application.StartupPath in a normal app)? OR if that is not possible is it possible in either Visual Studio or IIS to ensure that the xml file is copied across to the temp directory each time, and then user a local path (again something like Application.StartupPath) that will return the current temp directory to reference it... i.e. Application.StartupPath + @"\Settings.xml";

Any help here would be greatly appreciated, thanks for you time folks!

Mark

EDIT: The "random" directory the files are being run from is like this (but different) every time...

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temp orary ASP.NET Files\root\be744616\404c35e0\assembly\dl3\6bb73064 \0006a6c3_7987c901
Feb 24 '09 #1
3 9807
Frinavale
9,735 Expert Mod 8TB
@markmcgookin
I'm not sure what you're talking about here?

@markmcgookin
This is quite easy.
Just use the Server.MapPath method to map to the root directory of the application ("~/"):
Expand|Select|Wrap|Line Numbers
  1. Imports System.Web.Services
  2. Imports System.Web.Services.Protocols
  3. Imports System.ComponentModel
  4.  
  5. ' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
  6. ' <System.Web.Script.Services.ScriptService()> _
  7. <System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
  8. <System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
  9. <ToolboxItem(False)> _
  10. Public Class Service1
  11.     Inherits System.Web.Services.WebService
  12.  
  13.     <WebMethod()> _
  14.     Public Function ServicePath(ByVal person As String) As String
  15.         Return "My Path is: " + Server.MapPath("~/")
  16.     End Function
  17.  
  18. End Class
@markmcgookin
It sounds like your install program needs to be updated to make sure that the resources are in a location that your application expects them to be.

-Frinny
Feb 24 '09 #2
markmcgookin
648 Expert 512MB
Thanks Frin,

I am not a web services expert by any means, I have been asked to work on this with another developer who is the guy who created the service. He seemed to think that when the service is run some files are copied to that C:\WINDOWS\Microsoft.NET\Framework\... etc location.

Part of his code logs those file paths (I am not sure how, but I can't imagine it's being made up! hehe) we had used a .Net settings file because we thought it was going to be an xml file, and there is some xml to it, but VS seems to create and compile a C# file using this data and when we edit the xml on the server it doesn't affect the variables in the application.

Sorry to sound a bit like a n00b here, but I am just a humble mobile developer hehe.

So if we use that "Server.MapPath("~/")" variable, will that point to the directory that the web site is in in IIS? So we could reference an xml file in there? by going
Expand|Select|Wrap|Line Numbers
  1. string path = Server.MapPath("~/") + @"\myFile.xml";
  2.  
Thanks for the help.
Feb 24 '09 #3
Frinavale
9,735 Expert Mod 8TB
Hold on, back up.
Are you talking about client code or server code?

When you say that a file is being copied into:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temp orary ASP.NET Files\root\be744616\404c35e0\assembly\dl3\6bb73064 \0006a6c3_7987c901
Is this the client computer?
Or the server?
Feb 24 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Rob | last post by:
Hi, I am working on a project that requires a Windows Service which performs the following file transfer functions. 1. It monitors a specific local directory on a Windows 2003 Server. 2. When...
3
by: Daniel | last post by:
Is it possible to retain local file system read, write, delete access while impersonating for access to a remote drive in a different domain? I need to be able to move files from a local computer...
3
by: Shailesh Humbad | last post by:
I figured out what was causing the "Access is Denied" error when calling functions from referenced DLLs in my service. I've tried to be very detailed, so bear with me. It turns out that...
0
by: Kevin | last post by:
I'm writing a service in VB.NET. Reference the following code: Dim oStreamWriter As StreamWriter .... .... .... oStreamWriter = File.CreateText(TempLogFile) If Err.Number <> 0 Then...
0
by: David Hearn | last post by:
I have created a web service that will be running on one of our servers. It has a function in it called UploadFile. The way we would like to use it is the user types in the url...
2
by: ABCL | last post by:
Hi All, Can any one tell me that what is the difference between Network Service, Local Service and Local System ACcount for window services ABCL
1
by: MD | last post by:
Is it possible to load the local xml file and display in the div? Currently i tried the following source when i put it to web always gives me error saying "access is denied" <!DOCTYPE HTML...
5
by: abb | last post by:
On a Vista machine, the following code works using the ASP.NET Development Server, but fails in IIS7: book = excel.Workbooks.Open(tempfile, false, false, Missing.Value, Missing.Value,...
16
emibt08
by: emibt08 | last post by:
Hello fellow programmers. I am working on a project that is a windows service. It should open an excel file and read it and it worked good on WinXP SP2 w/ Office 2003. Now the customer upgraded to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
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,...
0
jinu1996
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.