November 2008
Beginner
320 pages
7h 6m
English
Now, create a custom method to retrieve the list of documents on the server. Rename the HelloWorld method to GetList(). Type the code for GetList shown in Example 12-6.
Example 12-6. THE GETLIST WEB METHOD
[WebMethod] public string GetList() { string filenames = ""; string[] files = System.IO.Directory.GetFiles(Server.MapPath("~/MyDocuments"), "*.*"); foreach (string s in files) { // Create the FileInfo object only when needed to ensure // the information is as current as possible. System.IO.FileInfo fi = null; try { fi = new System.IO.FileInfo(s); } catch (System.IO.FileNotFoundException e) { // To inform the user and continue is // sufficient for this demonstration. // Your application may require different behavior. Console.WriteLine(e.Message); ...Read now
Unlock full access