Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. How do you express file paths on the Website server from a Web service? [WORKAROUND]

How do you express file paths on the Website server from a Web service? [WORKAROUND]

Scheduled Pinned Locked Moved WPF
csharpdatabasequestionsql-serverwcf
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fjparisIII
    wrote on last edited by
    #1

    If I get this question answered, a lot of gaps in my understanding of Websites are going to be filled in, so hopefully someone will give me the answer. I have a WCF-based Web service for my Silverlight Website application and the Web service DLL is located in /bin off of the root of the Website. It has many services correctly accessing a SQL Server database and sending email to the client, so I know that it is set up correctly. Now, I have a bunch of JPEG files in /bin/ClientBin/SplashScreenPhotos. I would like to add another service that returns an ObservableCollection of JPEG file names (just the file names, not the whole path) to my Silverlight application. Once the application has that, it knows how to display those JPEG files, because it's doing it now with a list of file names hard-coded in the Silverlight application (hard-coding things is bad). My idea is to create a service that would look like this to populate the ObservableCollection:

    [OperationContract]
    public bool GetList(out ObservableCollection<string> list)
    {
    list = new ObservableCollection<string>();
    string folder = ???;
    string[] files = Directory.GetFiles(folder, "*.jpg");
    foreach (string path in files)
    {
    string fileOnly = System.IO.Path.GetFileName(path);
    list.Add(fileOnly);
    }
    return true;
    }

    My question thus is, what do I substitute for the ??? This is basically a question of how the service navigates through the Website file system. I've been fooling with this for hours without getting anywhere. Using paths like /bin/ClientBin/SplashScreenPhotos does not work. I'm thinking that I'm probably off-base in using the .NET Directory class to begin with, but I don't know what I should be using. [WORKAROUND added 2010-06-07]: I solved my problem through a fairly simple workaround. Instead of my service accessing my Website's file system directly (for all I know, something that is impossible), I used the FtpWebRequest class to do the job for me. The WebRequest.Method was WebRequestMethods.Ftp.ListDirectory, which returns a WebResponse object, from which you can create a StreamReader initialized with WebResponse.GetResponseStream(). I implemented the whole thing needed by the Web service through the following function, which the service calls:

    ObservableCollection<string> GetFileNamesFr

    F 1 Reply Last reply
    0
    • F fjparisIII

      If I get this question answered, a lot of gaps in my understanding of Websites are going to be filled in, so hopefully someone will give me the answer. I have a WCF-based Web service for my Silverlight Website application and the Web service DLL is located in /bin off of the root of the Website. It has many services correctly accessing a SQL Server database and sending email to the client, so I know that it is set up correctly. Now, I have a bunch of JPEG files in /bin/ClientBin/SplashScreenPhotos. I would like to add another service that returns an ObservableCollection of JPEG file names (just the file names, not the whole path) to my Silverlight application. Once the application has that, it knows how to display those JPEG files, because it's doing it now with a list of file names hard-coded in the Silverlight application (hard-coding things is bad). My idea is to create a service that would look like this to populate the ObservableCollection:

      [OperationContract]
      public bool GetList(out ObservableCollection<string> list)
      {
      list = new ObservableCollection<string>();
      string folder = ???;
      string[] files = Directory.GetFiles(folder, "*.jpg");
      foreach (string path in files)
      {
      string fileOnly = System.IO.Path.GetFileName(path);
      list.Add(fileOnly);
      }
      return true;
      }

      My question thus is, what do I substitute for the ??? This is basically a question of how the service navigates through the Website file system. I've been fooling with this for hours without getting anywhere. Using paths like /bin/ClientBin/SplashScreenPhotos does not work. I'm thinking that I'm probably off-base in using the .NET Directory class to begin with, but I don't know what I should be using. [WORKAROUND added 2010-06-07]: I solved my problem through a fairly simple workaround. Instead of my service accessing my Website's file system directly (for all I know, something that is impossible), I used the FtpWebRequest class to do the job for me. The WebRequest.Method was WebRequestMethods.Ftp.ListDirectory, which returns a WebResponse object, from which you can create a StreamReader initialized with WebResponse.GetResponseStream(). I implemented the whole thing needed by the Web service through the following function, which the service calls:

      ObservableCollection<string> GetFileNamesFr

      F Offline
      F Offline
      fjparisIII
      wrote on last edited by
      #2

      Well, it doesn't look as if anyone is interested in answering this question, or, incredibly, that no one monitoring this forum even knows what the answer is. Actually, it seems as if this is about as basic a Website question as a person could possibly ask, so maybe this is just the wrong forum: its answer may be so obvious to any Website developer worth his salt that he would have contempt for anyone who would even ask such a question. On the other hand, I've noticed very light activity on this Silverlight forum, indicating that there just aren't that many people out there yet doing serious work on this technology. So the only thing I can personally recommend to solve this problem is a workaround.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups