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.
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); ...
Get Microsoft® Visual Web Developer™ 2008 Express Edition Step by Step now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.