Beispiel #1
0
        // Rajdhani stoppped publishing epaper from 2016/09/16
        // so we are removing this item from comboxboxItem in the UI
        public void RajdhaniInfo()
        {
            // http://rajdhani.com.np/epaper/898 example link that holds the link to pdf file in <iFrame> tag
            // map the user input date to the date id like 898 in the above link
            DateTime dateLinkedWith898id = new DateTime(2016, 09, 16);
            TimeSpan span     = IssueDate.Subtract(dateLinkedWith898id);
            int      dateDiff = span.Days; // dateDiff +ve if IssueDate is greater than 2016/09/16 is -ve is IssueDate is less than 2016/09/16

            int dateId = (int)Math.Abs((decimal)898 + dateDiff);

            string linkToPdf = "http://rajdhani.com.np/epaper/" + dateId.ToString();

            // use Html agility package to extract link pdf link from <iFrame> tag
            HtmlWeb      web = new HtmlWeb();
            HtmlDocument doc = web.Load(linkToPdf);

            DownloadLinkAndFileName = new List <Dictionary <string, string> >();

            // select all iFrame tag using Xpath
            var iFrameTag = doc.DocumentNode.SelectNodes("//iframe");

            if (iFrameTag != null)
            {
                foreach (var tag in iFrameTag)
                {
                    string srcAttr = tag.Attributes["src"].Value;
                    if (srcAttr.Substring(0).Contains(".pdf"))
                    {
                        DownloadLinkAndFileName.Add(new Dictionary <string, string> {
                            { "dlLink", srcAttr },
                            { "filePathName", DownloadPath + "\\" + PaperName + "-" + _year + "-" + _month + "-" + _day + ".pdf" }
                        });
                    }
                }
            }
        }