Creating a Web Method

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.


 [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); ...

Get Microsoft® Visual Web Developer™ 2008 Express Edition Step by Step now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.