Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. #
  2. # // Clear any existing list contents
  3. # blFiles.Items.Clear();
  4. #
  5. # // Physical path name of the folder/directory we're interested in
  6. # string pn = Server.MapPath("~/Docs/examples");
  7. #
  8. # // Build the virtual path, done step-by-step to show you how it's done
  9. # // (you would probably combine some of the steps in your code)
  10. # // Virtual path name of this web application's root
  11. # string pathToWebAppRoot = Request.ApplicationPath;
  12. # // Path to the above folder, relative to this web app's root
  13. # string pathToFolder = "/Docs/examples/";
  14. # // Complete path to the above folder
  15. # string urlPath = pathToWebAppRoot + pathToFolder;
  16. #
  17. # try
  18. # {
  19. # // Now we're going to get the list of files and place the list into an array
  20. # String[] fileList = Directory.GetFiles(pn);
  21. #
  22. # // Next, we'll loop through the array's contents, and
  23. # // assign the file name to the bullet's visible text property,
  24. # // and the urlpath + file name to the value property
  25. # // The BulletedList control's DisplayMode property was set to HyperLink
  26. # for (int i = 0; i < fileList.Length ; i++)
  27. # {
  28. # // Create a new list item
  29. # ListItem li = new ListItem();
  30. # // Set its text property to the file name
  31. # li.Text = Path.GetFileName(fileList[i]);
  32. # // Set its value property to a URL
  33. # li.Value = urlPath + li.Text;
  34. # // Add the item to the bulleted list
  35. # blFiles.Items.Add(li);
  36. # }
  37. # // for (int i = 0; i < fileList.Length; i++)
  38. # }
  39. # catch (Exception ex)
  40. # {
  41. # blFiles.Items.Add("There was an error while creating this list:");
  42. # blFiles.Items.Add(ex.Message);
  43. # }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement