Tuesday, February 19, 2008

File Uploading And Downloading

//For file Uploading
if (FileUpload1.HasFile)
{
FileUpload1.SaveAs("D:\\weppage\\upload\\" + FileUpload1.FileName);
ListBox1.Items.Add(FileUpload1.FileName);
}


//For File Downloading
// Response.ContentType = "html/txt";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + ListBox1.SelectedValue.ToString() + "");
Response.TransmitFile("E:\\"+ListBox1.SelectedValue.ToString());
Response.End();

Friday, February 8, 2008

Code to find MAC Address in ASP.Net using VB.Net

using System;using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;using System.Data;
using System.Net;
using System.DirectoryServices;
using System.Runtime.InteropServices;

namespace GetMacAddressFromIPAddress
{
public class GetMacAddressFromIPAddress
{
[DllImport("iphlpapi.dll", ExactSpelling=true)]
public static extern int SendARP( int DestIP, int SrcIP, [Out] byte[] pMacAddr, ref int PhyAddrLen );
public string GetMacAddress(string sName)
{
string s = string.Empty ;
System.Net.IPHostEntry Tempaddr = null;
Tempaddr = (System.Net.IPHostEntry)Dns.GetHostByName(sName);
System.Net.IPAddress[] TempAd = Tempaddr.AddressList;
string[] Ipaddr = new string[3];
foreach(IPAddress TempA in TempAd)
{
Ipaddr[1] = TempA.ToString();
byte[] ab = new byte[6];
int len = ab.Length;
int r = SendARP( (int) TempA.Address, 0, ab, ref len );
string sMAC = BitConverter.ToString( ab, 0, 6 );
Ipaddr[2] = sMAC;
s = sMAC;
} return s;
}
}
}

Get Ip Address from Local Machine

String strHostName;

// Getting Ip address of local machine...
// First get the host name of local machine.

strHostName = DNS.GetHostName ();
Response.Write ("Local Machine's Host Name: " + strHostName);

// Then using host name, get the IP address list..
IPHostEntry ipEntry = DNS.GetHostByName (strHostName);
IPAddress [] addr = ipEntry.AddressList;
for (int i = 0; i < addr.Length; i++)
{
Response.Write("IP Address {0}: {1} " addr[i].ToString ());
}

Saturday, February 2, 2008

String Result = "";
foreach(DataGridItem dataGridItem in MyDataGrid.Items)
{

//Get name from cell[0]
String Name = dataGridItem.Cells[0].Text;

//Get text from textbox in cell[1]
String Age = ((TextBox)
dataGridItem.FindControl("AgeField")).Text;

//Get Checked property of Checkbox control
bool IsGraduate = ((CheckBox)dataGridItem.FindControl("IsGraduateField")).Checked;

// get Values from Checkboxlist
String Skills = "";
foreach(ListItem item in ((CheckBoxList)dataGridItem.FindControl("CheckBoxList1")).Items){
if (item.Selected)
{
Skills += item.Value + ",";
}
}
Skills = Skills.TrimEnd(',');

//Get RadioButtonList Selected text
String Experience = ((RadioButtonList)dataGridItem.FindControl("RadioButtonList1")).SelectedItem.Text;

//Get DropDownList Selected text String Degree = ((DropDownList)dataGridItem.FindControl("DropDownList1")).SelectedItem.Text;

// Build String to show result.
Result += Name;
Result += " [Age -" + Age + "] ";
if (IsGraduate)
{ Result += "Is Graduate , "; }
else{ Result += "Is not Graduate , "; }
Result += "Has Skills[" + Skills + "] , ";
Result += "Has " + Experience + " Experience , And " ;
Result += "Has " + Degree + " Degree." ;
Result += "
"; }
ResultField.Text = Result; }