Get link from HTML code anchor tag

Task: Get Link from HTML code anchor <a> tag using Asp.net and C# code.

Description:  Sometime we need to retrieve link from HTML code <a> tag Or sometime we need to modify/append/alter that link.
So in this function the HTML code is use as input and then we can retrieve link in that html code <a> tag.

Code: 

public void getlinkfromhtml(string content)
{
  int index = 0;
  do
  {
    int newindex = index + 5;
    index = content.IndexOf("href=", newindex);
    if (index > 0)
    {
      int index2 = content.IndexOf('\'', index + 6);
      int index3 = content.IndexOf('\"', index + 6);

      if (index3 > 0)
      {
        if (index2 > index3 || index2 == (-1))
            index2 = index3;
      }
      if (index2 > 0)
      {
        string href = content.Substring(index+6,(index2-(index + 6))).ToLower();

// Save/Use or do anything with this link href. You Can replace also this with another link.

      }
    }
  }
  while (index > 1);
}

View Pdf on browser using asp.net

Task: View Pdf on browser using asp.net.

Description: Here I show how we can view the pdf file on browser using asp.net and c#.

using System.Net;
public void viewebook(string pdf_filepath)
{
    string FilePath = Server.MapPath(pdf_filepath);
    WebClient User = new WebClient();
    Byte[] FileBuffer = User.DownloadData(FilePath);
    if (FileBuffer != null)
    {
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-length", FileBuffer.Length.ToString());
        Response.BinaryWrite(FileBuffer);
    }

}

Facebook feed using graph api

Task: Get Facebook page feed using graph api.

Description: As facebook depreciated old feed url (https://www.facebook.com/feeds/page.php?format=rss20&id=page_id). So now we need to use its graph api for this.

Here I describe how to get facebook page feed using graph api using javascript code. You just need to update your access token ( use app token as access token from here https://developers.facebook.com/tools/accesstoken/ ). 

you can run below url on your browser for all fields and can use as your requirements. In below code limit is use for how many post will return.

https://graph.facebook.com/1399557183635849/feed?access_token=224210267619471|gtYtk8w5_qPHbZkSpJ9pwD7Qy-8

https://graph.facebook.com/page_id/feed?access_token=yourapptoken



<script src="http://code.jquery.com/jquery-1.8.2.min.js" type="text/javascript"></script>
<script src="https://connect.facebook.net/en/all.js" type="text/javascript"></script>
<script>
 FB.api('https://graph.facebook.com/page_id/feed?access_token=yourapptoken', { limit: 20 }, function (response) {

 if (response && !response.error) {
 var msg='';
            for (var i = 0, l = response.data.length; i < l; i++) {
                var post = response.data[i];
                var userid = post.from.id;
                if (post.message) {                       
                    msg += '<span style="word-break: break-all;">'+ post.message  + '<br/><a  rel="nofollow" href='+post.link+'><img src=' +  post.picture  +' /></a>' + '</span><br/><br/>';                       
                }
                document.getElementById("sFbFeeds").innerHTML=msg;
            }
            }
            else
            {
               // alert('Error Occure');
            }
        });

        </script>
<div id="fb-root"></div>
<div id="sFbFeeds"></div>