asp.net - Source code of receiving email -


i making email client in asp.net c#. in it, gridview not taking data of more 5 rows. having 250 mails in mailbox. gridview not showing data. showing 5 rows , after 5 6 rows data presented out of gridview.

<%@ page language="c#" autoeventwireup="true" codefile="cs.aspx.cs" inherits="cs" %> <!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 runat="server"> <title></title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"> </script> <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/jquery-ui.js" type="text/javascript"> </script> <link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/themes/start/jquery-ui.css" rel="stylesheet" type="text/css"   /> <script type="text/javascript"> $("[id*=lnkview]").live("click", function () {     var subject = $(this).text();     var row = $(this).closest("tr");     $("#body").html($(".body", row).html());     $("#attachments").html($(".attachments", row).html());     $("#dialog").dialog({         title: subject,         buttons: {             ok: function () {                 $(this).dialog('close');             }         }     });     return false; }); </script> </head> <body style="font-family: arial; font-size: 10pt"> <form id="form1" runat="server"> <asp:gridview id="gvemails" runat="server" onrowdatabound="onrowdatabound" datakeynames="messagenumber" autogeneratecolumns="false"> <columns>     <asp:boundfield headertext="from" datafield="from" htmlencode="false" />     <asp:templatefield headertext="subject">         <itemtemplate>             <asp:linkbutton id="lnkview" runat="server" text='<%#           eval("subject") %>' />             <span class="body" style="display: none">                 <%# eval("body") %></span>         </itemtemplate>     </asp:templatefield>     <asp:boundfield headertext="date" datafield="datesent" />     <asp:templatefield itemstyle-cssclass="attachments">         <itemtemplate>             <asp:repeater id="rptattachments" runat="server">                 <itemtemplate>      <asp:linkbutton id="lnkattachment" runat="server" onclick="download" text='<%# eval("filename") %>' />                 </itemtemplate>                 <separatortemplate>                     <br>                 </separatortemplate>             </asp:repeater>         </itemtemplate>     </asp:templatefield> </columns> </asp:gridview> <div id="dialog" style="display: none"> <span id="body"></span> <br /> <span id="attachments"></span> </div> </form> </body>  </html> 

code behind:

public partial class cs : system.web.ui.page {  protected list<email> emails {     { return (list<email>)viewstate["emails"]; }     set { viewstate["emails"] = value; } }  protected void page_load(object sender, eventargs e) {     if (!ispostback)     {         this.read_emails();     } }  private void read_emails() {     pop3client pop3client;     if (session["pop3client"] == null)     {         pop3client = new pop3client();         pop3client.connect("pop.gmail.com", 995, true);         pop3client.authenticate("example@gmail.com", "password", authenticationmethod.tryboth);         session["pop3client"] = pop3client;     }     else     {         pop3client = (pop3client)session["pop3client"];     }     int count = pop3client.getmessagecount();     this.emails = new list<email>();     int counter = 0;     (int = count; >= 1; i--)     {         message message = pop3client.getmessage(i);         email email = new email()         {             messagenumber = i,             subject = message.headers.subject,             datesent = message.headers.datesent,             = string.format("<a href = 'mailto:{1}'>{0}</a>", message.headers.from.displayname, message.headers.from.address),         };         messagepart body = message.findfirsthtmlversion();         if (body != null)         {             email.body = body.getbodyastext();         }         else         {             body = message.findfirstplaintextversion();             if (body != null)             {                 email.body = body.getbodyastext();             }         }         list<messagepart> attachments = message.findallattachments();          foreach (messagepart attachment in attachments)         {             email.attachments.add(new attachment             {                 filename = attachment.filename,                 contenttype = attachment.contenttype.mediatype,                 content = attachment.body             });         }         this.emails.add(email);         counter++;         if (counter > count)         {             break;         }         gvemails.datasource = this.emails;         gvemails.databind();     }     //gvemails.datasource = this.emails;     //gvemails.databind(); } protected void onrowdatabound(object sender, gridviewroweventargs e) {     if (e.row.rowtype == datacontrolrowtype.datarow)     {         repeater rptattachments = (e.row.findcontrol("rptattachments") repeater);         list<attachment> attachments = this.emails.where(email => email.messagenumber == convert.toint32(gvemails.datakeys[e.row.rowindex].value)).firstordefault().attachments;         rptattachments.datasource = attachments;         rptattachments.databind();     } } protected void download(object sender, eventargs e) {     linkbutton lnkattachment = (sender linkbutton);     gridviewrow row = (lnkattachment.parent.parent.namingcontainer gridviewrow);     list<attachment> attachments = this.emails.where(email => email.messagenumber == convert.toint32(gvemails.datakeys[row.rowindex].value)).firstordefault().attachments;     attachment attachment = attachments.where(a => a.filename == lnkattachment.text).firstordefault();     response.addheader("content-disposition", "attachment;filename=" + attachment.filename);     response.contenttype = attachment.contenttype;     response.binarywrite(attachment.content);     response.end(); } }  [serializable]  public class email { public email() {     this.attachments = new list<attachment>(); } public int messagenumber { get; set; } public string { get; set; } public string subject { get; set; } public string body { get; set; } public datetime datesent { get; set; } public list<attachment> attachments { get; set; } }  [serializable] public class attachment { public string filename { get; set; } public string contenttype { get; set; } public byte[] content { get; set; } } 


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -