asp.net server path and generic resource invocation _ practical Tips

Source: Internet
Author: User
Page code:
Copy Code code as follows:

<%@ Page language= "C #" autoeventwireup= "true" codefile= "RadioButtonListDemo.aspx.cs"
inherits= "_default"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title> Untitled Page </title>
<body>
<form id= "Form1" runat= "Server" >
<div>
<asp:radiobuttonlist id= "Radiobuttonlist_demo" runat= "Server" onselectedindexchanged= "RadioButtonList_Demo_" SelectedIndexChanged "
Autopostback= "true" >
</asp:RadioButtonList>
<br/>
<asp:image id= "image_show" runat= "Server"/>
</div>
</form>
</body>

Background code:
Copy Code code as follows:

Using System;
Using System.Data;
Using System.Configuration;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;
Using CDataBase;
Using System.IO;
public partial class _default:system.web.ui.page
{
<summary>
Page load Events
</summary>
<param name= "Sender" > Control send Object </param>
<param name= "E" > Event object </param>
protected void Page_Load (object sender, EventArgs e)
{
Get the value of connectionstring
Response.Write ("<script>alert (' + sqlhelper.constring + ') </script>");
if (! IsPostBack)
{
To have the path system root directory under the Fuwa folder under the file path
String spath = Server.MapPath (Request.applicationpath + "/Fuwa/");
Get all the names below this path contains their path
string[] Sfiles = Directory.GetFiles (spath);
Loops the path of all files
foreach (String sfile in Sfiles)
{
Fetch file name
String sname = Path.getfilenamewithoutextension (sfile);
Take file name, include extension
String sfilename = Path.getfilename (sfile);
Establish the RadioButtonList of the Text/value, using the overloaded method of
ListItem Ritem = new ListItem (sname, Request.applicationpath + "/Fuwa/" + sfilename);
Add subkeys to RadioButtonList
RADIOBUTTONLIST_DEMO.ITEMS.ADD (Ritem);
}
To set the display arrangement of radio buttons in a RBL
Radiobuttonlist_demo.repeatdirection = RepeatDirection.Horizontal;
Radiobuttonlist_demo.repeatlayout = repeatlayout.table;
}
}
<summary>
Select Item Change Event
</summary>
<param name= "Sender" > Control send Object </param>
<param name= "E" > Event object </param>
protected void Radiobuttonlist_demo_selectedindexchanged (object sender, EventArgs e)
{
Image_show.imageurl = RadioButtonList_Demo.SelectedValue.ToString ();
}
}

Focus
Get the path to a directory under the site Directory
Using Server.MapPath (argurment)
Parameters using
Request.appliaction + "/directory Name/"
The meaning of this sentence is
Request a path under a directory under the server
All the file names under the path are finished
Through the directory object in System.IO
GetFiles (Request.appliaction) method
Only all file names under this directory can contain the extension
Path still need to use Request.application + "/file/" way to get
The note has been written very clearly.
You can practice.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.