hi
i had developed pop3 Account mail view in my web page
but i got error in (System.NullReference Exception: Object reference not set)
NetStrm.Write(szData, 0, szData.Length); - this line -
///my code start here (cs file)
-
using System;
-
using System.Data;
-
using System.Configuration;
-
using System.Web;
-
using System.Web.Security;
-
using System.Web.UI;
-
using System.Web.UI.WebControls;
-
using System.Web.UI.WebControls.WebParts;
-
using System.Web.UI.HtmlControls;
-
using System.Drawing;
-
using System.Collections;
-
using System.ComponentModel;
-
using System.Net;
-
using System.Net.Sockets;
-
using System.IO;
-
-
public partial class _Default : System.Web.UI.Page
-
{
-
public TcpClient testServername;
-
public NetworkStream NetStrm;
-
public StreamReader RdStrm;
-
public string Data;
-
public byte[] szData;
-
public string CRLF = "\r\n";
-
protected void Page_Load(object sender, EventArgs e)
-
{
-
-
}
-
protected void Button1_Click(object sender, EventArgs e)
-
{
-
string strpopservername = txtpopservername.Text;
-
string strusername = txtusername.Text;
-
string strpassword = txtpassword.Text;
-
-
//Cursor cr = Cursor.Current;
-
//Cursor.Current = Cursors.WaitCursor;
-
-
testServername = new TcpClient(strpopservername, 110);
-
//Status.Items.Clear();
-
-
try
-
{
-
// initialization
-
NetStrm = testServername.GetStream();
-
RdStrm = new StreamReader(testServername.GetStream());
-
//Status.Items.Add(RdStrm.ReadLine());
-
//Label1.Text = Label1.Text + RdStrm.ReadLine();
-
ListBox1.Items.Add(RdStrm.ReadLine());
-
-
// Login Process
-
Data = "USER " + strusername + CRLF;
-
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
-
NetStrm.Write(szData, 0, szData.Length);
-
//Status.Items.Add(RdStrm.ReadLine());
-
//Label1.Text = Label1.Text + RdStrm.ReadLine();
-
ListBox1.Items.Add(RdStrm.ReadLine());
-
-
Data = "PASS " + strpassword + CRLF;
-
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
-
NetStrm.Write(szData, 0, szData.Length);
-
//Status.Items.Add(RdStrm.ReadLine());
-
//Label1.Text = Label1.Text + RdStrm.ReadLine();
-
ListBox1.Items.Add(RdStrm.ReadLine());
-
-
-
// Send STAT command to get information ie: number of mail and size
-
Data = "STAT" + CRLF;
-
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
-
NetStrm.Write(szData, 0, szData.Length);
-
//Status.Items.Add(RdStrm.ReadLine());
-
//Label1.Text = Label1.Text + RdStrm.ReadLine();
-
ListBox1.Items.Add(RdStrm.ReadLine());
-
-
-
// change enabled - disabled button
-
Butconnect.Enabled = false;
-
Butdisconnect.Enabled = true;
-
ButRetrieve.Enabled = true;
-
//ConnectBtn.Enabled = false;
-
// DisconnectBtn.Enabled = true;
-
// RetrieveBtn.Enabled = true;
-
-
// back to normal cursor
-
//Cursor.Current = cr;
-
-
}
-
catch (InvalidOperationException err)
-
{
-
//Status.Items.Add("Error: " + err.ToString());
-
//Label1.Text = "Error: " + err.ToString();
-
ListBox1.Items.Add("Error: " + err.ToString());
-
}
-
-
}
-
protected void Butdisconnect_Click(object sender, EventArgs e)
-
{
-
-
-
}
-
protected void ButRetrieve_Click(object sender, EventArgs e)
-
{
-
// change cursor into wait cursor
-
//Cursor cr = Cursor.Current;
-
//Cursor.Current = Cursors.WaitCursor;
-
string szTemp;
-
//Message.Clear();
-
Label2.Text = "";
-
try
-
{
-
// retrieve mail with number mail parameter
-
Data = "RETR " + txtnumber.Text + CRLF;
-
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
-
//NetStrm.Write(szData, 0, szData.Length);
-
NetStrm.Write(szData, 0, szData.Length);
-
-
szTemp = RdStrm.ReadLine();
-
if (szTemp[0] != '-')
-
{
-
-
while (szTemp != ".")
-
{
-
Label2.Text += szTemp + CRLF;
-
szTemp = RdStrm.ReadLine();
-
}
-
}
-
else
-
{
-
ListBox1.Items.Add(szTemp);
-
}
-
-
// back to normal cursor
-
//Cursor.Current = cr;
-
-
}
-
catch (InvalidOperationException err)
-
{
-
ListBox1.Items.Add("Error: " + err.ToString());
-
}
-
catch (System.Exception ex)
-
{
-
ListBox1.Items.Add("Error : " + ex.ToString());
-
}
-
-
}
-
}
-
///my code end here
pls guide me
Thanks
4 2058
Wouldn't you need to Connect() your TcpClient before trying to write data to it?
hi
thanks for ur reply
can u send code
pls
thanks
Wouldn't you need to Connect() your TcpClient before trying to write data to it?
hi
thanks for ur reply
can u send code
pls
thanks
...
testServername.Connect()
hi
thanks for ur reply
can u send code
pls
thanks
NullReferenceException simply means that you tried to dereference a null. In that line you are dereferencing two objects. NetStr and szData. If you do a Console.WriteLine of those variables before the call you will see which one is null.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: roger |
last post by:
Here's a weird one...
The code below works just fine when I build in DEBUG mode.
Today, I tried to build my solution in RELEASE mode, and
immediately fell over this problem - apparently...
|
by: Andras Serfozo Jr via .NET 247 |
last post by:
(Type your message here)
Hello, I am having problems with a Microsoft XML example from VBat the Movies/Data and XML/Read XML Files.
I created the program just like in the movie and it works up...
|
by: Seth Broomer |
last post by:
Can someone please tell me what might be causeing this error. I get it
every once in a while.
I just noticed this also...where it says c:\sethbacup\d...
that is where i do my build. But then i...
|
by: kscdavefl |
last post by:
When I try to display the fields associated with a table using the following
code:
private void fieldsButton_Click(object sender, System.EventArgs e)
{
string tableName =...
|
by: David Lozzi |
last post by:
Howdy,
I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders!
Now I am making a public function that will take the...
|
by: XML newbie: Urgent pls help! |
last post by:
I am using VB.Net. My program is to connect to a remote IPAddress. Once, it
verifies the login information it should display the SessionID and enable
some button . I appreciate your help and thanku...
|
by: XML newbie: Urgent pls help! |
last post by:
I am using VB.Net. My program is to connect to a remote IPAddress. Once, it
verifies the login information it should display the SessionID and enable
some button . I appreciate your help and thanku...
|
by: eoinmoon |
last post by:
Hi all,
New to C# and VS 5 and .NET. I have attempted to write a service via
various examples and after several failed attempts to write an
installer via the VS 5 wizards,etc I tried to install...
|
by: Steve |
last post by:
Hi All
I have a windows forms Application (SAM) in vb.net 2008 using .net framework
V2
One and only one customer out of 30 customers is getting errors daily where
they have to close and...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |