මොකද්ද මේ XML Post ??

මොකද්ද මේක කියල දැන ගන්න (තියරි - පොතේ දැනුම ) ගන්න ආවනම් ඔබට හරියන ලිපිය මේක නෙවෙයි. (ගූග්ල් එකෙන් එව්ව හොයා ගන්න පුලුවන් ලේසියෙන්ම )
මම කියන්න යන්න සරල XML Post එකක් යවා ගන්න විදිහක්.
ඉස්සෙල්ලම වෙබ් පිටුවක් හදාගමු XML post එකක් අරගෙන සරලව txt file එකකට ගහන විදිහට.

private void Page_Load(object sender, EventArgs e)
        {
            Page.Response.ContentType = "text/xml";
            // Read XML data posted through HTTP
            StreamReader reader = new StreamReader(Page.Request.InputStream);
            String xmlData = reader.ReadToEnd();
            StreamWriter test = new StreamWriter(Server.MapPath("temp.txt"), true);
            test.Write(DateTime.Now  +" " + xmlData.ToString ());
            test.Close();
        }
හරි දැන් ඕකට xml එකක් යවන්න තියෙන්නෙ මොකක් හරි වෙන වැඩසටහනකින්.
සරලව යවන මෙතඩ් එකක් පල්ලෙහා තියෙන විදිහට අපිට හදා ගත්තැහැකි.

 public void DoXMLPost(string xmlData)
        {
            WebRequest req = null;
            WebResponse rsp = null;
            try
            {
                string uri = ConfigurationSettings.AppSettings["HTTPPostURL"].ToString(); ;
                req = WebRequest.Create(uri);
                //req.Proxy = WebProxy.GetDefaultProxy ();  // Enable if using proxy
                req.Method = "POST";        // Post method
                req.ContentType = "text/xml";     // content type
                // Wrap the request stream with a text-based writer
                StreamWriter writer = new StreamWriter(req.GetRequestStream());
                // Write the XML text into the stream
                writer.WriteLine(xmlData);
                writer.Close();
                // Send the data to the webserver
                rsp = req.GetResponse();

            }
            catch (WebException webEx)
            {
                throw webEx;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (req != null) req.GetRequestStream().Close();
                if (rsp != null) rsp.GetResponseStream().Close();
            }
        }
මෙව්ව ඉතින් එහෙන් මෙහෙන් හොයාගෙන මම එදිනෙදා පාවිච්චියට හරියන විදිහට මගෙ සිතුම් පැතුම් වල ඔබින විදිහට වෙනස් කරල තියෙන්නෙ. මතක නැහැ කොහෙන් ගත්තද කියල.
මොකක් හරි අවුලක් හරි මම කරල තියෙන විදිහෙ වැරැද්දක් හරි තියෙනව නම් කියන්න.


කියවපු විද්‍යුත් ලිපි එව්වෙ කවුද ??

මම කලින් ලිපියෙ සඳහන් කලානෙ කොහොමද එන ලිපියක් කියවන්නෙ කියල. කියෙව්වට මදිනෙ එව්වෙ කව්ද කියලත් හොයාගන්න ඔනෙ නෙ.

item.Recipients කිව්ව්ම කට්ටියගෙම නම් ටික හම්බ වෙනව. ප්‍රශ්නයක් නැහැ ඔයාට ඔනෙ එවපු කෙනාගෙ, යවපු කෙනාගෙ, කොපි වෙච්ච කට්ටියගෙ නම් ලැයිස්තුවනම් ඔනෙ. නිකම්ම ලූප් එකක් දාල ගන්න එකනෙ.

අවුල තියෙන්නෙ ඒ කට්ටියගෙ ලිපිනය xxx@xxx.xxx වගේ විදිහකට ගන්න ඔනෙ උනොත් පොඩි කචල් එකක් යනව (Recipient ගෙ Adress prperty එක එන්නෙ /O=TEST SYSTEMS INC./OU=EMPLOYEE/cn=Recipients/cn=GayanBalasooriya වගේ විදිහකට). ඉතින් ලිපිනය නිකම්ම ගන්න බැහැ. (පුලුවන් ක්‍රමයක් තියෙනවනම් මටත් කියන්න)
ඉතින් මේකත් විසඳගන්න ව්දිහක් හම්බ උන මෙන්න මේ ආකාරයට.

 foreach (Microsoft.Office.Interop.Outlook.Recipient rec in item.Recipients )
           {
                 string AddressOnSomethingAtSomethingFormat = this.GetSMTPAddress(rec.Address );
            }
මෙතඩ් එක එන්නෙ මෙන්න මේ විදිහට
public string GetSMTPAddress(String strAddress)
        {
            Microsoft.Office.Interop.Outlook.ContactItem contactItem = null;
            String strKey;
            String strRet;           

            contactItem = (Microsoft.Office.Interop.Outlook.ContactItem)app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olContactItem);
            contactItem.Email1Address = strAddress;

            strKey = "_" + DateTime.Now.Ticks;
            contactItem.FullName = strKey;
            contactItem.Save();
            strRet = contactItem.Email1DisplayName.Replace("(", "").Replace(")", "").Replace(strKey, "").Trim (); 
            contactItem.Delete();
            contactItem = null;

            contactItem = (Microsoft.Office.Interop.Outlook.ContactItem)ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderDeletedItems).Items.Find("[Subject]=" + strKey);
            if (contactItem != null)
                contactItem.Delete();

            return strRet;

        }
මේකෙදි මොකද්ද වෙන්නෙ කියල ඔනේ කෙනෙකුට තේරෙයි පොඩ්ඩක් කෝඩ් එක කියෙව්ව නම්.
මම වැඩිය විස්තර කරන්නෙ නැත්තෙ මොකද; නැත්නම් කට්ටිය නිකම්ම කෝඩ් එක කොපි කරගෙන මුකුත් ඉගෙන ගන්නෙ නැති නිසා.
මොකක් හරි අවුලක්,කොස්සක්,තේරෙන්නෙ නැති තැනක් තියෙනවනම් අහන්න මම කොහොම හරි උත්තර දෙන්නම්.

විද්‍යුත් තැපැල් කියවමු

මම දන්නව කට්ටිය ඕනෙ තරම් පාවිච්චි කරල ඇති Microsoft office Outlook 2007 විද්‍යුත් තැපැල් කියවන්න. නමුත් මම කියන්නෙ යන්නෙ outlook 2007 වලින් නිකම්ම කියවන හැටි නොවේ.

මම පාවිච්චි කරන්නෙ C#.net. මම පෙන්නන පහත දැක්වෙන method එකෙන් මේල් කියවනව. කියවල එන MailItem එකට අපිට ඕනෙ දෙයක් කරන්න පුලුවන්.

Outlook DLL පාවිච්චි කරන නිස මේකෙන් mail කියවන්න,යවන්න,contacts හදන්න,calendar item දාන්න වගෙ outlook පාව්ච්චි කරල කරන ඕනෙ දෙයක් කරන්න පුලුවන්. 

 public void ReadUnReadMail()
        {
            string userName = ConfigurationSettings.AppSettings["UserName"].ToString();
            string password = ConfigurationSettings.AppSettings["Password"].ToString();
            Microsoft.Office.Interop.Outlook.MailItem item = null;
            try
            {
                app = new Microsoft.Office.Interop.Outlook.Application();
               
                ns = app.GetNamespace("MAPI");
                ns.Logon(userName, password, false, true);

                inboxFolder = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);

                for (int i = 1; i <= inboxFolder.Items.Count; i++)
                {
                    item = (Microsoft.Office.Interop.Outlook.MailItem)inboxFolder.Items[i];

                    if (item != null)
                    {
                        //do what ever you want
                    } 
                }
            }
            catch (Exception  ex)
            {               
                System.Diagnostics.EventLog myEventLog = new System.Diagnostics.EventLog();
                myEventLog.Log = "Application";
                myEventLog.Source = "what ever";
                myEventLog.WriteEntry(ex.ToString());
            }
            finally
            {
                ns = null;
                app = null;
                inboxFolder = null;
            }
        }
ඇත්තටම මම මෙක ලිව්වෙ හෙනට ඉන්ටනෙට් එකේ හොයල. නමුත් මට මතක නැහැ කොහෙන් කොහෙන් මෙව්ව හොයා ගත්තද කියල.

මොනව උනත් මෙකේ තේරෙන්නෙ නැති හරි වැඩ කරන්නෙ නැති හරි මොකක් හරි සීන් එකක් තියෙනවනම් අහන්න මම කොහොම හරි පුළුවන් විදිහකට උත්තර දෙන්නම්.