O'Reilly logo

Microsoft® Visual Web Developer™ 2008 Express Edition Step by Step by Eric Griffin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required