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 asp.net 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 asp.net 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()
{
try
{
    string filePath = Server.MapPath(@"FolderName\file.jpg");
    string FtpUrl =  "ftp://ftp.domain.com/";
    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);
    stream.Close();
    FtpWebResponse res = (FtpWebResponse)req.GetResponse();
    return res.StatusDescription;
}
catch (Exception ex)
{
    return "";
}

}