Remove new line from title tag created dynamically

Task:  Remove extra new line from dynamically created title tag 

Description: Remove extra new line from dynamically created title tag.  As previously we created Title tag (Title of page) using code (Link) for SEO purpose. There is a little issue with Title tag, It takes extra new line but in SEO we want to remove this new line. we can use this in Master Page so that we needn't to rewrite it for every page.

using System.Reflection;
public static void InitializeTitleTag()
    Type type = typeof(HtmlTextWriter);
    FieldInfo field = type.GetField("_tagNameLookupArray", BindingFlags.Static | BindingFlags.NonPublic);
    Array lookup = (Array)field.GetValue(null);
    int index = (int)HtmlTextWriterTag.Title;
    object value = lookup.GetValue(index);
    type = value.GetType();
    field = type.GetField("tagType");
    field.SetValue(value, 0);
    lookup.SetValue(value, index);


Upload file via FTP using c#

Task: Generally we used FileZilla or any other FTP software for uploading a file on Web Server. Here we can also use our c# code for that. FTP file upload using and c#.

Description: We can upload our file via FTP using C#.

using System.Net;
using System.Text.RegularExpressions;
using System.IO;
public string UploadFile()
    string filePath = Server.MapPath(@"FolderName\file.jpg");
    string FtpUrl =  "";
    string userName = "ftp_user";      
    string password =   "ftp_password";
    string UploadDirectory = "";
    string PureFileName = new FileInfo(filePath).Name;
    String uploadUrl = String.Format("{0}{1}/{2}", FtpUrl, UploadDirectory, PureFileName);
    FtpWebRequest req = (FtpWebRequest)FtpWebRequest.Create(uploadUrl);
    req.Proxy = null;
    req.Method = WebRequestMethods.Ftp.UploadFile;
    req.Credentials = new NetworkCredential(userName, password);
    req.UseBinary = true;
    req.UsePassive = true;
    byte[] data = File.ReadAllBytes(filePath);
    req.ContentLength = data.Length;
    Stream stream = req.GetRequestStream();
    stream.Write(data, 0, data.Length);
    FtpWebResponse res = (FtpWebResponse)req.GetResponse();
    return res.StatusDescription;
catch (Exception ex)
    return "";


Get link from HTML code anchor tag

Task: Get Link from HTML code anchor <a> tag using 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.


public void getlinkfromhtml(string content)
  int index = 0;
    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);