@manhng

Welcome to my blog!

Compare Two Folders

February 4, 2021 23:00

Compare Two Folders (edit)

How to compare the contents of two folders (LINQ) (C#) | Microsoft Docs

c# - How to compare Files in two different Folders and perform conditional copying - Stack Overflow

Compare directories to see which files are in both in C#C# Helper (csharphelper.com)

How to Compare the Contents of Two Folders and Synchronize them - Winhelponline

How to Compare the Contents of Two Folders and Synchronize them - Winhelponline

  • Microsoft WinDiff
  • WinMerge
  • FreeFileSync
  • XCopy
  • RoboCopy
  • Microsoft SyncToy
  • SyncFolder
  • Total Commander

Compare Two Objects

Comparing Objects In C# (c-sharpcorner.com)

How to compare two objects (testing for equality) in C# (grantwinney.com)

Code POST to login form to get cookie from Response (HtmlAgilityPack)

using HtmlAgilityPack;
using System;
using System.Collections.Specialized;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;

namespace ConsoleApp9
{
/// <summary>
/// Using CookieContainer and WebClient To Access ASP MVC anti-CSRF enabled Websites
/// https://matthewgladney.com/blog/web-apps/using-cookiecontainer-and-webclient-to-access-asp-mvc-anti-csrf-enabled-websites/
/// </summary>
internal class Program
{
private static void Main(string[] args)
{
var values = new NameValueCollection();
values.Add("username", "manh");
values.Add("password", "manh");
var cookieAwareWebClient = new CookieAwareWebClient();
cookieAwareWebClient.Login("http://localhost:5000/Account/LogOn", values);
}
}

public class CookieAwareWebClient : WebClient
{
public CookieAwareWebClient(CookieContainer container)
{
CookieContainer = container;
}

public CookieAwareWebClient()
: this(new CookieContainer())
{ }

public CookieContainer CookieContainer { get; private set; }

protected override WebRequest GetWebRequest(Uri address)
{
var request = (HttpWebRequest)base.GetWebRequest(address);
request.CookieContainer = CookieContainer;
return request;
}

/// <summary>
/// #2 – Establish a Get Request
/// </summary>
/// <param name="url"></param>
/// <param name="CookieContainer"></param>
/// <returns></returns>
public HtmlDocument GetPage(string url, CookieContainer CookieContainer)
{
Uri absoluteUri = new Uri("http://localhost:5000/Account/LogOn");
var cookies = CookieContainer.GetCookies(absoluteUri);

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.CookieContainer = new CookieContainer();
foreach (Cookie cookie in cookies)
{
request.CookieContainer.Add(cookie);
}
request.Method = "GET";

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
var stream = response.GetResponseStream();

using (var reader = new StreamReader(stream))
{
string html = reader.ReadToEnd();
var doc = new HtmlDocument();
doc.LoadHtml(html);
return doc;
}
}

public void Login(string loginPageAddress, NameValueCollection loginData)
{
CookieContainer container;
var request = (HttpWebRequest)WebRequest.Create(loginPageAddress);
request.Method = "GET";
container = request.CookieContainer = new CookieContainer();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
var stream = response.GetResponseStream();
using (var reader = new StreamReader(stream))
{
HtmlNode.ElementsFlags.Remove("form");
string html = reader.ReadToEnd();
var doc = new HtmlDocument();
doc.LoadHtml(html);
var input = doc.DocumentNode.SelectSingleNode("//*[@name='__RequestVerificationToken']");
var token = input.Attributes["value"].Value;

loginData.Add("__RequestVerificationToken", token);
loginData.Add("returnURL", "");
}

var request2 = (HttpWebRequest)WebRequest.Create(loginPageAddress);
request2.CookieContainer = new CookieContainer();
foreach (Cookie cookie in response.Cookies)
{
request2.CookieContainer.Add(cookie);
}

request2.Method = "POST";
request2.ContentType = "application/x-www-form-urlencoded";
var buffer = Encoding.ASCII.GetBytes(GenerateQueryString(loginData));
request2.ContentLength = buffer.Length;
var requestStream = request2.GetRequestStream();
requestStream.Write(buffer, 0, buffer.Length);
requestStream.Close();

var response2 = request2.GetResponse();
try
{
string cookie = response2.ResponseUri.Query.Split('=')[1];
Console.WriteLine(string.Format("Cookies: {0}", cookie));
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
}
response2.Close();
CookieContainer = request2.CookieContainer;
}

public string GenerateQueryString(NameValueCollection collection)
{
var array = (from key in collection.AllKeys
from value in collection.GetValues(key)
select string.Format("{0}={1}", WebUtility.UrlEncode(key), WebUtility.UrlEncode(value))).ToArray();
return string.Join("&", array);
}
}
}

Programmatically: Login and get cookie from response

Using CookieContainer and WebClient To Access ASP MVC anti-CSRF enabled Websites - MatthewGladney.com (HAY HAY HAY)

htmlagilitypack - programmatically login to website using c# for web scraping - Solved (i-harness.com) (HAY HAY HAY)

Get ASP.NET auth cookie using PowerShell (when using AntiForgeryToken) | James Crowley (HAY HAY HAY)

Topic: accept a cookie while using Invoke-WebRequest | PowerShell.org (HAY HAY HAY)

WebRequest Login for Page Scraping Flickr | The ASP.NET Forums (HAY HAY HAY)

Automating Web Login with HttpWebRequest – Steve Fenton

How to get __RequestVerificationToken Cookie without browser? (microsoft.com)

HTTP POSTs and HTTP GETs with WebClient and C# and Faking a PostBack - Scott Hanselman's Blog

What Are Anti Cross-site Request Forgery Tokens And What Are They Good For? » Adam.Kahtava.com / AdamDotCom

httpwebrequest - Sending NameValueCollection to http request C# - Stack Overflow

Categories

Recent posts