Your Ad Here

Asp.Net TextBox To Ms-Access In C#

AIM : Asp.Net TextBox To Microsoft Access In C# Language.

LIVE DEMO : NA ( Not Available ) .

CODE : Download The Source Code HERE . I want to briefly explain what this Code contains . Here I have used the Following Code. This code could be used and cut-copy-pasted in thebutton click event . Any doubts may be leaved as Comments

OleDbConnection oleDbConnection = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0; Data Source=" + Server.MapPath("~/db.mdb"));

OleDbCommand oleDbCommand = new OleDbCommand();

oleDbCommand.Connection = oleDbConnection;

oleDbCommand.CommandText = "INSERT INTO Table1 (Name , Surname )VALUES ('" + TextBox1.Text + "', '" + TextBox2.Text + "')";
oleDbConnection.Open();

oleDbCommand.ExecuteNonQuery();

oleDbConnection.Close();



Add new Page Dynmically

AIM : Add new Page Dynmically

LIVE DEMO : NA ( not Available ) .

CODE : Download The Source Code HERE
I want to briefly explain what this Code contains . There are  Textboxes in One you will write the name of the page and a random string will be attached to it so that to avoid overwriting of files . And click the button . 2 things will happen . It will create that page and also redirect u to that page .

Getting A Geographical Location From Ip Address

AIM : To get Geographical Location using Internet Protocol .

LIVE DEMO :


CODE : To Download The Source Code Click HERE
Well what I exactly did is I used the services of http://freegeoip.appspot.com/ . It provides free Geographic location to all the users. I have made an API using that . Look the source code

WARNING ::::: IF YOU ARE RUNNING ON LOCALHOST THE LOCATION WILL APPEAR THAT OF JAPAN , TOKYO . UPLOAD IT ON SERVER AND ENJOY

Comment Box in ASP.NET (XML)

Download The Code
AIM : 1.When User Enters A code In Textbox It must Go to An XML window and at the same time Viewable At the Page .
2.There Must Be a Cpatcha In Place sot that We can Know whether It is A bot or Not .
3. Admin must Be able To delete Unwanted Comments .

How : Just Download the CODE

Images :

Procedure :
Well In Default.aspx.cs Write the following Code:
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
readXML();
}
protected void butAdd_Click(object sender, EventArgs e)
{
if (txtName.Text == "" || txtUserComment.Text == "" )
lblStatus.Text = "Please complete the form.";
else
{
Captcha1.ValidateCaptcha(txtCaptcha.Text.Trim());
if (Captcha1.UserValidated)
{
}
else
{
lblStatus.Text = "Invalid Captcha ";
}
XDocument xmlDoc = XDocument.Load(Server.MapPath("People.xml"));
xmlDoc.Element("Comments").Add(new XElement("Comment", new XElement("Name", txtName.Text),
new XElement("UserComment", txtUserComment.Text)));
xmlDoc.Save(Server.MapPath("People.xml"));
lblStatus.Text = "Comment Successfully Published";
readXML();
}
}
protected void readXML()
{
XDocument xmlDoc = XDocument.Load(Server.MapPath("People.xml"));
var Comments = from Comment in xmlDoc.Descendants("Comment")
select new
{
Name = Comment.Element("Name").Value,
UserComment = Comment.Element("UserComment").Value,
};
litResults.Text = "";
foreach (var Comment in Comments)
{
litResults.Text = litResults.Text + "Name: " + Comment.Name + " ";
litResults.Text = litResults.Text + "Comment: " + Comment.UserComment + " ";
}
if (litResults.Text == "")
litResults.Text = "No Comments";
}
protected void Button1_Click(object sender, EventArgs e)
{
}
}

In Default.aspx write the Following Code :

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register assembly="MSCaptcha" namespace="MSCaptcha" tagprefix="cc1" %>
<!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 id="Head1" runat="server">
<title>Using AJAX, LINQ and XML together in ASP.NET 3.5 and C#.NET</title>
</head>
<body>
<div align="left" >
<form id="form1" runat="server">
<table style="width:100%;">
<tr>
<td style="margin: 10px">
&nbsp;Comments Posted Alredy --------<br />
<br />
<asp:Literal ID="litResults" runat="server" /></td>
</tr>
</table><br />
<br />
POST A COMMENT :<br />
<table style="width:40%; margin-top: 0px;">
<tr>
<td class="style3">
&nbsp; NAME</td>
<td class="style2">
<asp:TextBox ID="txtName" runat="server" Width="222px" /></td>
</tr>
<tr>
<td class="style4">
COMMENT</td>
<td class="style5">
<asp:TextBox ID="txtUserComment" runat="server" Height="86px" TextMode="MultiLine"
Width="224px" /></td>
</tr>
<tr>
<td class="style3">
CAPTCHA</td>
<td class="style2">
<cc1:CaptchaControl ID="Captcha1" runat="server" CaptchaLength="1"
Width="100px" CaptchaWidth="100" LineColor="Brown" NoiseColor="Azure"
CssClass="me" /> <asp:TextBox ID="txtCaptcha" runat="server" Width="50px"></asp:TextBox> <br />
<br />
<asp:Button ID="butAdd" runat="server" Text="Post Comment" onclick="butAdd_Click" />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Label ID="lblStatus" runat="server" ForeColor="#FF3300" />
</td> </tr> </table>
<br /><br /> <br /> <br /> </div> </form>
</body>
</html>

Note: There must be MSCaptcha.dll in the Bin Folder you can Download it from The Above Link
Note: There must Be People.xml in the Same Folder as in that of Code . This Code also works in UserControl .
If there is any Problem Please leave it In Comment

ASP.NET Textbox Value To XML Page

You Can Download The Code FROM HERE . Well in Deafault.aspx.cs Type the following CODE :

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;


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


    }


    protected void butRead_Click(object sender, EventArgs e)
    {
       lblStatus.Text = "";
    }


    protected void butAdd_Click(object sender, EventArgs e)
    {
        try
        {
            
                XDocument xmlDoc = XDocument.Load(Server.MapPath("dotnetsnippets.xml"));
                
                xmlDoc.Element("Vaibhav").Add(new XElement("Anything", new XElement("V1", v1.Text),
                new XElement("V2", v2.Text)));


                xmlDoc.Save(Server.MapPath("dotnetsnippets.xml"));
                lblStatus.Text = "Data successfully added to XML file.";
                
            
        }
        catch
        {
            lblStatus.Text = "Sorry, unable to process request. Please try again.";
        }
    }


}

The Default.aspx Code here --


<%@ 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 id="Head1" runat="server">
    <title>XML BY VAIBHAV MAHESHWARI</title>
</head>
<body>

        <br />
        &nbsp;<br />
        <br />
        <br />
      
    <fieldset style="width: 804px" align="center">
 
    <legend>XML BY VAIBHAV MAHESHWARI</legend>
    <div align="left" style="text-align: center">

    <form id="form1" runat="server">
        <strong>Add to XML</strong><br />
        Enter Anything:<br />
        <asp:TextBox ID="v1" runat="server" /><br />
        Enter Anything:<br />
        <asp:TextBox ID="v2" runat="server" /><br />
        <br />
        <asp:Button ID="butAdd" runat="server" Text="Add" onclick="butAdd_Click" /><br />
        <asp:Label ID="lblStatus" runat="server" />
        <br />
    </form>
  
   </div>
    </fieldset>
</body>
</html>

NOTE ::::::: there must be file named dotnetsnippets.xml in the same folder and it must contain the following CODE  

<?xml version="1.0" encoding="utf-8"?>
<Vaibhav>
</Vaibhav>