How do you express file paths on the Website server from a Web service? [WORKAROUND]
-
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 theObservableCollection
:[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 .NETDirectory
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 theFtpWebRequest
class to do the job for me. TheWebRequest.Method
wasWebRequestMethods.Ftp.ListDirectory
, which returns aWebResponse
object, from which you can create aStreamReader
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
-
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 theObservableCollection
:[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 .NETDirectory
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 theFtpWebRequest
class to do the job for me. TheWebRequest.Method
wasWebRequestMethods.Ftp.ListDirectory
, which returns aWebResponse
object, from which you can create aStreamReader
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
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.