DaddyCode Team Blog
C# , ASP.NET, MVC, SQL, Sharepoint, JQuery and nowt else from a Web Developer in Leeds
3 Nov 2021
Tenda Nova MW12 MW6 cannot connect to wireless printer on mesh network from wired computer
17 Mar 2021
Download SFTP file and send to Azure Blob Storage with minimal memory usage
In Azure we use the Renci SSH.NET library to download a file from an SFTP server and put it into Blob Storage.
Our first approach was simple: Downloading the file in entirety to memory, and then uploading to blob store.
using (var memStream = new MemoryStream()) { sftpClient.DownloadFile("sftpFilePath", memStream); memStream.Position = 0; var container = cloudBlobClient.GetContainerReference("blobContainerName"); var blob = container.GetBlockBlobReference("blobName"); await blob.UploadFromStreamAsync(memStream); }
However, we soon realized this approach meant we consumed as much memory as the file's size. We fixed this by instead opening a writeable stream to the blob, and connecting that directly to the sftp client's DownloadFile method:
var container = cloudBlobClient.GetContainerReference("blobContainerName"); var blob = container.GetBlockBlobReference("blobName"); using (var blobStream = blob.OpenWrite()) { sftpClient.DownloadFile("sftpFilePath", blobStream); }
Note however that with this approach you may run into the limit of 100,000 uncommitted blocks that azure blob storage enforces. We have to select the block size, which is the size of each "chunk" of blob that the SDK uploads. You do this by setting the blob's StreamWriteSizeInBytes property, which can be between 16Kb and 100Mb. So for 4Mb blocks, do:
blob.StreamWriteSizeInBytes = 4 * 1024 * 1024;
However, in version 11.1.0.0 of the azure storage library, we noticed that this setting seemed to be ignored when using OpenWrite, and the actual block size was something like 5Kb! This meant we hit the uncommitted block error for files over 450Mb in size. So, to handle very large file uploads we had to instead revert to using UploadFromStreamAsync (which does honour the StreamWriteSizeInBytes property), and had to do some extra work to surface the reading stream to pass to it.
1 Feb 2021
Find and kill a Windows 10 process on a given port
FIND the naughty process PID:
netstat -a -n -o | findstr *PORT_#_HERE*
KILL the naughty process:
taskkill /f /pid *PID_#_HERE*
9 Apr 2018
Windows 10 Start Menu "Best Match" won't open
The solution is also annoying. There's a folder in your AppSettings that you're going to need to delete:
C:\Users\YOUR_USERNAME\AppData\Local\Packages\Microsoft.Windows.Cortana_cw5n1h2txyewy
However, you can't delete it while you're logged in. So you're going to need to:
- Create a new user, or use an existing other account that isn't currently logged in.
- Make it Admin or give it write permissions on your user folder mentioned above.
- Log out of your problem account.
- Log into the new account.
- Find the folder mentioned above and delete it.
- Log out of the new account.
- Log back into your old account and the problem should be fixed.
- Don't forget to remove Admin role from the other user and remove any permissions you gave it.
1 May 2017
Pick up Emails from IMAP
using (ImapClient client = new ImapClient("server.name", 993, "account.name", "account.passwd", AuthMethod.Login, true)) { IEnumerable<uint> uids = client.Search(SearchCondition.SentSince(DateTime.Now.AddDays(-7))); IEnumerable<mailmessage> messages = client.GetMessages(uids, FetchOptions.HeadersOnly); }
20 Jan 2017
Visual Studio 2015 crashes with "has stopped working" when searching Entire Solution
22 Sept 2016
IIS 503 Service Unavailable - Classic ASP
In IIS I saw that the Classic ASP App Pool had stopped. But if restarted, it just stopped again when I hit the website.
Event Viewer said "The Module DLL C:\WINDOWS\system32\inetsrv\rewrite.dll failed to load. The data is the error." This is the IIS Rewrite 2 module.
So I went into Programs and Features, located "IIS URL Rewrite Module 2" and hit "Repair".
Then I restarted the crashed Classic App Pool in IIS, viewed the website, and the problem was fixed.
13 Nov 2015
Use Technicolor modem as slave wireless access point
1) Used "other" easy setup wizard to gain access to turn off DHCP on slave router
2) Set slave IP to be out of the DHCP range of the main router, but within the subnet.
3) Setup wifi SSID, password etc to match the main router, but use different wireless channel.
4) Put slave at opposite end of house, connected over powerline.
Bingo... Seamless wireless transition throughout the house and garden. Can also connect devices to the slave via cable.
11 Sept 2015
Bluetooth Issues with Lenovo ThinkPad T410 - Error 1935
I tried to fix by downloading the latest ThinkPad Bluetooth with Enhanced Data Rate Software for Windows 7 and reinstalling, but it kept failing with the dreaded Error 1935. An error occurred during the installation of assembly 'Microsoft.VC80.ATL error.
The only thing that fixed this was by running the Microsoft Fix It tool, telling it that I had a problem with Installing the Thinkpad Bluetooth software. It fixed stuff, rebooted my machine (without asking!) and I was then able to install the software.
17 Mar 2015
IIS 7 URL Rewrite - Ensure SSL/HTTPS and Ensure Fully Qualified Domain Name (FQDN) as Hostname
After installing URL Rewrite 2.0 on IIS, this was achieved by adding the following to the site's root web.config file.