You are on page 1of 10

WEB APP (C#)

CN Lab Final

WAIZ YOUSUF
200401057
EE 19 A
Task:
Create a web survey app in C# that asks for name and
cell phone number. All data submitted through web form
should be stored in a text file.

Software used: Visual Studio

Web App Designing


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

<!DOCTYPE html>
<html>
<head>
<title>Web Survey App</title>
<style type="text/css">
.auto-style1 {
font-size: x-large;
}
.auto-style2 {
text-align: left;
background-color: #003399;
}
.newStyle1 {
font-family: Fixedsys;
}
.newStyle2 {
font-family: Verdana;
}
.newStyle3 {
font-family: Verdana;
}
.auto-style3 {
background-color: #FFFFFF;
}
.auto-style5 {
background-color: #FFFFFF;
}
.auto-style6 {
color: #FFFFFF;
font-weight: 700;
font-size: x-large;
background-color: #0066FF;
}
.auto-style7 {
color: #FFFFFF;
background-color: #6699FF;
}
</style>
</head>
<body style="height: 150px">
<form id="Form1" runat="server" class="auto-style1">
<div class="auto-style2">
<div class="auto-style2">
<label for="txtName" class="newStyle3"><span class="auto-style7">Enter your
Name:</span></label>&nbsp;&nbsp;
<asp:TextBox ID="txtName" runat="server" required CssClass="auto-style5"
Height="19px" Width="136px"></asp:TextBox>
</div>

<div class="auto-style2">
<span class="newStyle2">
<label for="txtCellPhone"><span class="auto-style7">Enter your Phone
Number:</span></label></span>&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="txtCellPhone" runat="server" required pattern="\d{10}"
CssClass="auto-style3" Height="22px" Width="142px"></asp:TextBox>
</div>

<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;&nbsp;&nbsp;&nbsp;&nbsp;

<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click"


CssClass="auto-style6" Height="41px" Width="115px" />
</div>
</form>
</body>
</html>

Design View

Name and Number Entry code (C#)


using System;
using System.IO;
using System.Web.UI;

namespace WebSurveyApp
{
public partial class Default : Page
{
protected void btnSubmit_Click(object sender, EventArgs e)
{
string name = txtName.Text;
string cellPhoneNumber = txtCellPhone.Text;

string filePath = Server.MapPath("~/App_Data/surveyData.txt");


string surveyData = string.Format("Name: {0}, Cell Phone Number: {1}", name,
cellPhoneNumber);

// Write the survey data to a text file


File.AppendAllText(filePath, surveyData + Environment.NewLine);

Response.Redirect("ThankYou.aspx");
}
}
}
ThankYou Page Design code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ThankYou.aspx.cs"
Inherits="WebSurveyApp.ThankYou" %>

<!DOCTYPE html>
<html>
<head>
<title>Thank You</title>
<style type="text/css">
.auto-style1 {
font-weight: normal;
text-decoration: underline;
color: #000000;
}
.auto-style3 {
font-size: larger;
background-color: #CCCCCC;
}
.auto-style4 {
color: #000000;
font-size: x-large;
width: 437px;
background-color: #C0C0C0;
}
</style>
</head>
<body>
<h1 class="auto-style1"><strong><span class="auto-style3">Thank
You!</span></strong></h1>
<p class="auto-style4">Your survey has been submitted successfully.</p>

<a href="Default.aspx">Add another response</a>


</body>
</html>
Results
Another app that allows searching for phone number using in that text file.

Web App Designing

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"


Inherits="PhoneNumberSearchApp.Default" %>

<!DOCTYPE html>
<html>
<head>
<title>Phone Number Search</title>
<style type="text/css">
.auto-style1 {
font-style: italic;
color: #000066;
font-size: xx-large;
background-color: #CCFFFF;
}
.auto-style2 {
color: #000066;
}
.auto-style3 {
color: #000066;
font-size: xx-large;
background-color: #FFFF99;
}
.auto-style4 {
font-size: xx-large;
background-color: #66CCFF;
}
.auto-style5 {
text-align: center;
}
.auto-style6 {
font-weight: normal;
}
.auto-style7 {
background-color: #99CCFF;
}
.auto-style8 {
font-style: italic;
color: #000066;
font-size: xx-large;
background-color: #FFCCFF;
}
</style>
</head>
<body>
<form id="Form1" runat="server">
<div class="auto-style5">
<span class="auto-style2">
<label for="txtName"><span class="auto-style4"><strong class="auto-
style6"><span class="auto-style7">Enter Name:</span></strong></span></label></span> <em>
<asp:TextBox ID="txtName" runat="server" CssClass="auto-style8" Height="35px"
Width="237px"></asp:TextBox>
</em>
</div>

<p class="auto-style5">

<asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="btnSearch_Click"


CssClass="auto-style1" Height="43px" Width="159px" />
</p>
<div class="auto-style5">

<asp:Label ID="lblResult" runat="server" EnableViewState="false" CssClass="auto-


style3"></asp:Label>
</div>
</form>

</body>
</html>

Design View
Searching Code
using System;
using System.IO;
using System.Web.UI;

namespace PhoneNumberSearchApp
{
public partial class Default : Page
{
protected void btnSearch_Click(object sender, EventArgs e)
{
string nameToSearch = txtName.Text;

string filePath = Server.MapPath("~/App_Data/surveyData.txt");

// Read the text file line by line


string[] lines = File.ReadAllLines(filePath);

string phoneNumber = null;

// Search for the phone number using the name


foreach (string line in lines)
{
if (line.Contains("Name: " + nameToSearch))
{
// Extract the phone number from the line
phoneNumber = line.Split(':')[2].Trim();
break;
}
}

if (phoneNumber != null)
{
lblResult.Text = "Phone number of " + nameToSearch + " : " +
phoneNumber + "";
}
else
{
lblResult.Text = "Phone number not found.";
}
}
}
}
Results

You might also like