Hi mahesh213,
The PowerStatus belongs to System.Windows.Forms namespaces.
So you need to add the reference of System.Windows.Forms in your project.
Then inserit the System.Windows.Forms namespace to use it.
Check this example. Now please take its reference and correct your code.
HTML
Charger Status:
<asp:TextBox runat="server" ID="txtChargeStatus" /><br />
Full Life:
<asp:TextBox runat="server" ID="txtFullLifetime" /><br />
Charge:
<asp:TextBox runat="server" ID="txtBatteryPercent" /><br />
Life Remaining:
<asp:TextBox runat="server" ID="txtLifeRemaining" /><br />
Line Status:
<asp:TextBox runat="server" ID="txtPowerLineStatus" />
Namespaces
C#
using System.Windows.Forms;
VB.Net
Imports System.Windows.Forms
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
PowerStatus status = SystemInformation.PowerStatus;
txtChargeStatus.Text = status.BatteryChargeStatus.ToString();
txtFullLifetime.Text = status.BatteryFullLifetime == -1 ? "Unknown" : status.BatteryFullLifetime.ToString();
txtBatteryPercent.Text = status.BatteryLifePercent.ToString("P0");
txtLifeRemaining.Text = status.BatteryLifeRemaining == -1 ? "Unknown" : status.BatteryLifeRemaining.ToString();
txtPowerLineStatus.Text = status.PowerLineStatus.ToString();
}
VB.Net
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim status As PowerStatus = SystemInformation.PowerStatus
txtChargeStatus.Text = status.BatteryChargeStatus.ToString()
txtFullLifetime.Text = If(status.BatteryFullLifetime = -1, "Unknown", status.BatteryFullLifetime.ToString())
txtBatteryPercent.Text = status.BatteryLifePercent.ToString("P0")
txtLifeRemaining.Text = If(status.BatteryLifeRemaining = -1, "Unknown", status.BatteryLifeRemaining.ToString())
txtPowerLineStatus.Text = status.PowerLineStatus.ToString()
End Sub