******Question 2 <html><head> <title>Q2 p1</title> </head> <body> <form method=post action=Q2a.asp> <pre> Your Name: <input type= textbox name= emailt size="20"> Your Email : <input type= textbox name= emailt size="20" > Target Email: <input type= textbox name= emailt size="20" > </pre> <input type= submit name=Submit> </form> </body></html> *****Q2a.asp <html><head> </head> <body> <% session("nam") = request.form("emailt")(1) session("semail") = request.form("emailt")(2) session("temail") = request.form("emailt")(3) %> <form method=post action=Q2b.asp> Enter a text file name with content of Email: <input type= textbox name= content size="20"> <input type= submit name=Submit> </form> </body></html> *****Q2b.asp <html><head></head> <body> <% filec = request.form("content") Set fsoObject = CreateObject("Scripting.FileSystemObject") if fsoObject.FileExists(Server.Mappath(filec)) Then set tso = fsoObject.OpenTextFile(Server.Mappath(filec), 1, false, 0) temp = tso.readALL set tso = nothing Set objMessage = CreateObject("CDO.Message") objMessage.Subject = "Example CDO Message" objMessage.Sender = session("semail") objMessage.To = session("temail") objMessage.TextBody = temp objMessage.Send set objMessage=nothing End If %> </body></html> 1 *****Question 3 ***Q3.asp <html> <body> <FORM METHOD="POST" ACTION="upload.asp" ENCTYPE="multipart/form-data"> <input type = "file" name ="data" > <input type = "submit" value = "go"> </form> </body></html> *** Upload.asp <html> <body> <% Set obj = Server.CreateObject("aspSmartUpload.SmartUpload") obj.Upload obj.Save(Server.Mappath("\syedstud\ASPupload\progtest")) uploadname = obj.Files.Item(1).FileName Session("filepath") = Server.Mappath("\syedstud\ASPupload\progtest") & "\" & obj.Files.Item(1).FileName %> <center><h2>Following grades extracted from file</h2></center> <center><table> <form action ="final.asp" method = "post"> <% set fso = server.createObject("scripting.FileSystemObject") Set tso = fso.OpenTextFile(Server.Mappath("\syedstud\ASPupload\progtest\" & uploadname), 1, false,0) response.write("<Table border=1>") while not tso.AtEndOfStream response.write("<tr><td>") temp = tso.readline response.write(replace(temp, ",", "</td><td>")) response.write("</td></tr>") wend response.write("</Table>") set tso = nothing set fso = nothing %> </table></center> <center>Store in the DataBase?<br> <input type = "radio" name = "store" value ="yes">Yes <input type = "radio" name = "store" value ="no">No <input type = "submit" value ="submit"></center><br> </form> </body> </html> *** final.asp <html><body> <% if request.form("store") = "yes" then 'connect to the database - Make sure your path is correct strconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("position.mdb") SET objConn = Server.CreateObject("ADODB.Connection") objConn.Open strconn set fso = server.createObject("scripting.FileSystemObject") 2 Set tso = fso.OpenTextFile(Session("filepath"), 1, false,0) Set objRec = Server.CreateObject ("ADODB.Recordset") while not tso.AtEndOfStream templine = tso.readline myarray = Split(templine,",") query ="Insert into tblgrade values('" & myarray(0) & "', " & myarray(1) & ", " & myarray(2) & ", " & myarray(3) & ", " & myarray(4) & ")" response.write(query) objRec.Open query, objConn wend set tso = nothing set fso = nothing set objRec = nothing objConn.close end if %> </body></html> Using VB.NET for Q3 *** HTML Page <%@ Page Language="vb" AutoEventWireup="false" Codebehind="midq3.aspx.vb" Inherits="probtest.midq3"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <title>midq3</title> <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR"> <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE"> <meta content="JavaScript" name="vs_defaultClientScript"> <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema"> </HEAD> <body MS_POSITIONING="GridLayout"> <form id="Form2" method="post" encType="multipart/form-data" runat="server"> <INPUT id="File1" style="Z-INDEX: 101; LEFT: 80px; WIDTH: 248px; POSITION: absolute; TOP: 56px; HEIGHT: 32px" type="file" size="22" name="File1" runat="server"> <asp:button id="btnupload" style="Z-INDEX: 102; LEFT: 80px; POSITION: absolute; TOP: 96px" runat="server" Text="upload" Height="32px" Width="120px"></asp:button> <asp:label id="lblmsg" style="Z-INDEX: 103; LEFT: 376px; POSITION: absolute; TOP: 64px" runat="server" Height="56px" Width="312px"></asp:label> <asp:table id="Table1" style="Z-INDEX: 104; LEFT: 80px; POSITION: absolute; TOP: 176px" runat="server" Height="144px" Width="208px" GridLines="Both" BorderWidth="2px" BorderColor="#000040"> </asp:table> <asp:radiobuttonlist id="rad1" style="Z-INDEX: 105; LEFT: 96px; POSITION: absolute; TOP: 336px" runat="server" Height="40px" Width="128px" Visible="False"> <asp:ListItem Value="Yes">Yes</asp:ListItem> <asp:ListItem Value="No">No</asp:ListItem> </asp:radiobuttonlist> <asp:button id="btndb" style="Z-INDEX: 106; LEFT: 96px; POSITION: absolute; TOP: 408px" runat="server" Text="Store in DB" Height="32px" Width="88px" Visible="False"></asp:button> </form> </body></HTML> 3 **** Code Behind Imports System.IO Imports System.Data.SqlClient Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here End Sub Private Sub btnupload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnupload.Click If Not File1.PostedFile Is Nothing And File1.PostedFile.ContentLength > 0 Then Dim fn As String = System.IO.Path.GetFileName(File1.PostedFile.FileName) Dim SaveLocation As String = Server.MapPath("Data") & "\" & fn 'Response.Write("No of Files: " & Request.Files.Count) Session("flpath") = SaveLocation Try File1.PostedFile.SaveAs(SaveLocation) lblmsg.Text = "The file " & fn & " has been uploaded and length is: " & File1.PostedFile.ContentLength & " bytes<BR><BR>" Dim myfile As New System.IO.StreamReader(SaveLocation) Dim oneLine As String Dim myarray(4) As String oneLine = myfile.ReadLine() While (oneLine <> "") Dim cellCtr As Integer myarray = Split(oneLine, ",") Dim tRow As New TableRow For cellCtr = 0 To 4 Dim tCell As New TableCell tCell.Text = myarray(cellCtr) tRow.Cells.Add(tCell) Next Table1.Rows.Add(tRow) oneLine = myfile.ReadLine() End While myfile.Close() rad1.Visible = True btndb.Visible = True Catch Exc As Exception lblmsg.Text = "Error: " & Exc.Message End Try Else lblmsg.Text = "Please select a file to upload." End If End Sub Private Sub btndb_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndb.Click If rad1.SelectedItem.Value() = "Yes" Then Try Dim SaveLocation As String = Session("flpath") Dim myfile As New System.IO.StreamReader(SaveLocation) Dim strConString As String = "Password=syedstud1234;Persist Security Info=True;User ID=syedstud;Initial Catalog=testsyed;Data Source=mssql.cs.mnsu.edu,1400" Dim objSqlConn As New SqlConnection(strConString) 4 objSqlConn.Open() Dim oneLine As String Dim myarray(4) As String oneLine = myfile.ReadLine() While (oneLine <> "") Dim strSQL As String Dim fldCtr As Integer myarray = Split(oneLine, ",") strSQL = "Insert into tblgrade values('" & myarray(0) & "'" For fldCtr = 1 To 4 strSQL += ", " & myarray(fldCtr) Next strSQL += ")" Dim objSqlCommand = New SqlCommand(strSQL, objSqlConn) objSqlCommand.ExecuteNonQuery() oneLine = myfile.ReadLine() End While myfile.Close() lblmsg.Text = "Data saved in the database." rad1.Visible = False btndb.Visible = False Catch Exc As Exception lblmsg.Text = "Error: " & Exc.Message End Try End If End Sub An alternative method in VB.NET for Q3 ****** HTML page <%@ Page Language="vb" AutoEventWireup="false" Codebehind="midq3v1.aspx.vb" Inherits="probtest.midq3v1"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <title>midq3v1</title> <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR"> <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE"> <meta content="JavaScript" name="vs_defaultClientScript"> <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema"> </HEAD> <body MS_POSITIONING="GridLayout"> <form id="Form1" method="post" runat="server"> <INPUT id="File1" style="Z-INDEX: 101; LEFT: 48px; WIDTH: 360px; POSITION: absolute; TOP: 104px; HEIGHT: 24px" type="file" size="40" name="File1" runat="server"> <asp:datagrid id="DataGrid1" style="Z-INDEX: 102; LEFT: 48px; POSITION: absolute; TOP: 224px" runat="server" Width="336px" Height="200px" AutoGenerateColumns="False"> <AlternatingItemStyle ForeColor="#000040" BackColor="#E0E0E0"></AlternatingItemStyle> <HeaderStyle Font-Names="Tahoma" ForeColor="#000040" BackColor="#C0C0FF"></HeaderStyle> <Columns> <asp:BoundColumn DataField="Name" HeaderText="NAME"></asp:BoundColumn> <asp:BoundColumn DataField="Grade1" HeaderText="GRADE1"></asp:BoundColumn> <asp:BoundColumn DataField="Grade2" HeaderText="GRADE2"></asp:BoundColumn> <asp:BoundColumn DataField="Grade3" HeaderText="GRADE3"></asp:BoundColumn> <asp:BoundColumn DataField="Grade4" HeaderText="GRADE4"></asp:BoundColumn> </Columns> 5 </asp:datagrid> <asp:button id="Button1" style="Z-INDEX: 103; LEFT: 48px; POSITION: absolute; TOP: 144px" runat="server" Width="112px" Text="UpLoad"></asp:button> <asp:label id="lblmsg" style="Z-INDEX: 104; LEFT: 432px; POSITION: absolute; TOP: 104px" runat="server" Width="232px" Height="64px"></asp:label> <asp:RadioButtonList id="radlist" style="Z-INDEX: 105; LEFT: 432px; POSITION: absolute; TOP: 256px" runat="server" Width="72px" Height="40px" Visible="False"> <asp:ListItem Value="yes">yes</asp:ListItem> <asp:ListItem Value="no">no</asp:ListItem> </asp:RadioButtonList> <asp:Button id="btndb" style="Z-INDEX: 106; LEFT: 424px; POSITION: absolute; TOP: 344px" runat="server" Width="160px" Height="32px" Text="Save To DataBase" Visible="False"></asp:Button></form> </body> </HTML> *******Code Behind Private al As New ArrayList Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If Not File1.PostedFile Is Nothing And File1.PostedFile.ContentLength > 0 Then Dim fn As String = System.IO.Path.GetFileName(File1.PostedFile.FileName) Dim SaveLocation As String = Server.MapPath("Data") & "\" & fn Response.Write("No of Files: " & Request.Files.Count) Try File1.PostedFile.SaveAs(SaveLocation) lblmsg.Text = "The file " & fn & " has been uploaded and length is: & File1.PostedFile.ContentLength & " bytes<BR><BR>" Dim file As New System.IO.StreamReader(SaveLocation) Dim oneLine As String Dim myarray(4) As String oneLine = file.ReadLine() While (oneLine <> "") myarray = Split(oneLine, ",") al.Add(New grade(myarray(0), myarray(1), myarray(2), myarray(3), myarray(4))) oneLine = file.ReadLine() End While file.Close() DataGrid1.DataSource = al DataGrid1.DataBind() radlist.Visible = True btndb.Visible = True File1.Visible = False Button1.Visible = False Catch Exc As Exception lblmsg.Text = "Error: " & Exc.Message End Try Else lblmsg.Text = "Please select a file to upload." End If End Sub Private Sub btndb_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndb.Click Similar to the previous way of solving End Sub 6 " *******grade Class File: grade.vb Public Class grade Private Private Private Private Private g_name As String g_grade1 As Short g_grade2 As Short g_grade3 As Short g_grade4 As Short Public Sub New(ByVal Name, ByRef Grade1, ByVal Grade2, ByVal Grade3, ByVal Grade4) g_name = Name g_grade1 = Grade1 g_grade2 = Grade2 g_grade3 = Grade3 g_grade4 = Grade4 End Sub Public Property Name() As String Get Return g_name End Get Set(ByVal Value As String) g_name = Value End Set End Property Public Property Grade1() As String Get Return g_grade1 End Get Set(ByVal Value As String) g_grade1 = Value End Set End Property Public Property Grade2() As String Get Return g_grade2 End Get Set(ByVal Value As String) g_grade2 = Value End Set End Property Public Property Grade3() As String Get Return g_grade3 End Get Set(ByVal Value As String) g_grade3 = Value End Set End Property Public Property Grade4() As String Get Return g_grade4 End Get Set(ByVal Value As String) g_grade4 = Value End Set End Property End Class 7 8