hi
i had developed pop3 Account mail view in my web page
but i got error in (System.NullRef erence Exception: Object reference not set)
NetStrm.Write(s zData, 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 2081 Plater 7,872
Recognized Expert Expert
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?
Plater 7,872
Recognized Expert Expert
hi
thanks for ur reply
can u send code
pls
thanks
...
testServername. Connect()
hi
thanks for ur reply
can u send code
pls
thanks
NullReferenceEx ception 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.WriteLi ne 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 something
in the order or sequencing or something regarding static
initialization.
Consider this class, which implements a singleton pattern:
|
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 towhere the combo box gets populated. When I select a customerfrom the list it is supposed to populate text fields with theother customer info. Instead I get a Unhandled exception of Type'System.Null Reference Exception' occured / Object reference...
|
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 copy over my files to a diffrent
server. Why is that path not shown?
thanks
seth
Error Message: Object reference not set to an instance of an object.
|
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 = tablesList.SelectedItem.ToString();
string con = connectLabel.Text;
cn = new System.Data.OleDb.OleDbConnection(con);
cn.Open();
|
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 path of the uploaded image, and resize it with the provided dimensions. My function is below. The current function is returning an error when run from the upload function: A generic error occurred in GDI+. Not sure what exactly that means. From what...
| |
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 in advance
When I run the pgm , I get the error:
Can't parse login information. Namespace Manager or XsltContext needed. This
query has a prefix, variable or userdefined function.
I have added the Try-catch in all my functions. In...
|
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 in advance
When I run the pgm , I get the error:
Can't parse login information. Object Reference not set to an instance of an
object. I have added the Try-catch in all my functions. In ParseLoginResponse
function, it catches the above...
|
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 the service
manually using Installutil.exe utility.
Unfortunately I am getting an error very early on, during the
Installation phase which has left me totally stumped as I don't know
how to go about fixing this.
|
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 restart my application, sometimes several times a day
The customer has XP Home SP2
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |