Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6582045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:13:53+00:00 2026-05-25T16:13:53+00:00

I have a web service with a svc file and a codebehind that defines

  • 0

I have a web service with a svc file and a codebehind that defines a simple web service using WCF.

Obviously I am hosting the web service on a server using the svc file.

My service needs to access a file in the directory of the web application where the web service resides.

Consider that following structure:

Web application root folder: MyWebApp

MyWebApp (folder) -> Images (folder)

MyWebApp (folder) -> App_Code (folder)

MyWebApp (folder) -> WebServices (folder)

MyWebApp (folder) -> Data (folder)

MyWebApp (folder) -> Web.config (file)

MyWebApp (folder) -> WebServices (folder) -> MyWebService.svc (file)

MyWebApp (folder) -> App_Code (folder) -> MyWebService.cs (file)

MyWebApp (folder) -> Data (folder) -> myfile.txt

Well. From the csharp file codebehind web service file I would like to access the xml file located in the appropriate folder for data.

How should I do this??? I cannot have access to a Server object of course…

Thankyou

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T16:13:54+00:00Added an answer on May 25, 2026 at 4:13 pm

    If you are hosting in IIS:

    var root = HostingEnvironment.ApplicationPhysicalPath;
    var someFile = Path.Combine(root, "images", "test.png");
    

    Now of course this being said you should absolutely never write such code in a WCF service operation. You should have this service take the path as constructor argument and then simply configure your dependency injection framework to pass the correct value:

    public class MyService1: IMyService
    {
        private readonly string _path;
        public MyService1(string path)
        {
            _path = path;
        }
    
        public void SomeServiceOperation()
        {
            var someFile = Path.Combine(_path, "images", "test.png");
            // TODO: do something with the file
        }
    }
    

    Now all that’s left is to write a custom IInstanceProvider to wire up your dependency injection framework. This way the code of your service is no longer dependent on how/where is the service hosted. All that this service needs is a file path => inject it into it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have .svc file of web service and now I want to use that
I have a web service that queries data from this json file, but I
I have a simple .Net web service. When I visit the /webservice.svc path in
In my web project I have a TestStreamingService.svc file containing a REST service. The
A WCF service named Portal.WebServices.TaskListService uses a codebehind file TaskListService.svc.cs . In this file
I have a WCF service that runs in my web application that provides data
I have a WCF RESTful web service (using the webHttpBinding) running under IIS, exposed
I have made a REST Web service, that works with Visual Studios WCF Test
I have a WCF web service called Palladium that is created as a project
I have a .NET 3.5 based web service running at http://localhost/serivce.svc/ . Then I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.