Well ! controls needed : controls used

This example demonstrates the followings

  • DirectoryInfo dirinfo = new DirectoryInfo(Server.MapPath(""));
  • string machineName = Server.MachineName.ToString();
  • string _gettype = Server.GetType().ToString();
  • string _session = Session.ToString();
  •  Server.UrlPathEncode(Server.MapPath(""));
  • DataGrid : DG1.DataSource = dirinfo.GetFiles("*.*");
    DG1.DataBind();

Step: 1 Create a website http://manas6/aspnet.35/mm.FileStream11/

 

Step: 2 Code

Default.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

DirectoryInfo dirinfo = new DirectoryInfo(Server.MapPath(""));
string machineName = Server.MachineName.ToString();
string _gettype = Server.GetType().ToString();
string _session = Session.ToString();

Label1.Text += "Computer Name " + machineName + "<br/>" + "GetType : " + _gettype;
Label1.Text += "<br/>Session " + _session.ToString() + "<br/>" + "Server.UrlPathEncode : " + Server.UrlPathEncode(Server.MapPath(""));
DG1.DataSource = dirinfo.GetFiles("*.*");
DG1.DataBind();

}
protected void Transfer_Button_Click(object sender, EventArgs e)
{
Server.Transfer("Default2.aspx");

}

}
 

Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
<asp:DataGrid runat="server" id="DG1" Font-Name="Verdana"
AutoGenerateColumns="False" AlternatingItemStyle-BackColor="#eeeeee"
HeaderStyle-BackColor="Navy" HeaderStyle-ForeColor="White"
HeaderStyle-Font-Size="15pt" HeaderStyle-Font-Bold="True">
<Columns>
<asp:HyperLinkColumn DataNavigateUrlField="Name" DataTextField="Name"
HeaderText="File Name" />
<asp:BoundColumn DataField="LastWriteTime" HeaderText="Last Write Time"
ItemStyle-HorizontalAlign="Center" DataFormatString="{0:d}" />
<asp:BoundColumn DataField="Length" HeaderText="File Size"
ItemStyle-HorizontalAlign="Right"
DataFormatString="{0:#,### bytes}" />
</Columns>
</asp:DataGrid>
<asp:Button ID="Transfer_Button" runat="server" Text="Transfer"
onclick="Transfer_Button_Click" />
</div>
</form>
</body>
</html>
 


 

Step: 3

Runtime analysis

Testing URL's for web pages; Click on Default.aspx (Default.aspx.cs code pages are not accessible)

Reading Text file