Tuesday, August 14, 2018

how to quickly write a console application to delete file within period of time with .Net Core

when we a console application to clean some historical files from the folder, we will add an app settings section in the app.config file in project, which is run under .net framework. however it is much flexible to run with .Net Core.

i will show you my first sample DotNet Core Console App to handle this task.

1. Launch Visual Studio and create a  new project by selecting the Console App (.Net Core)



2.  Open the management studio and select the project, then right click to show the menu, select Add to get the New Item from slide out menu. to add JSon Config file





3.  Open the JSon file and filll with the following information

 {
  "PrintFolder": "the folder you want to delete files",

  "FileExtension": ".pdf",

  "DaysToMaintain":  "15"
}




4. Load the config information into the program using the snippet of code below

IConfiguration config = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.Build();
var fileExtension = config["FileExtension"];
var daysToKeepFiles = -1* Convert.ToInt32(config["DaysToMaintain"]);
var ltlPrintFolder = config["LTLPrintFolder"];
Console.WriteLine($"ltl print folder path : { ltlPrintFolder}");


5. Use the LINQ to manipulate the logic on what kind of file and Periods based on the file creation time.
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(ltlPrintFolder); IEnumerable<System.IO.FileInfo> fileList = dir.GetFiles("*.*", System.IO.SearchOption.AllDirectories);
 IEnumerable<System.IO.FileInfo> fileQuery =
                from file in fileList
                where file.Extension == fileExtension && file.CreationTime < DateTime.Now.AddMonths(daysToKeepFiles)
                orderby file.Name
                select file;




6. loop through the result from the query

foreach (System.IO.FileInfo fi in fileQuery)
            {
                Console.WriteLine(fi.FullName);
                fi.Delete();
            }


Now you can delete file with Dot Net Core App









Tuesday, June 26, 2018

How to solve contact can not remove from skype for business?

after some team mate or colleagues left the team, we might just keep their contacts in our skype contact list. eventually the contact will be displayed as unavailable, when we try to remove them from the list. we click on the confirmation button, but the contact never have been able to removed from list.

the quick solution is very easy and quick.

First  we need to completely exit from Skype applicatio.

Second  launch the outlook portal in light mode

https://outlook.office365.com/owa/?exsvurl=1&layout=light 

 Third click on the Contact Folder on the left navigation panel


Four. Type in contact name in the filter textbox, then select it and delete, then re-launch your Skype for business, we will see those contacts should be all gone.


Monday, March 5, 2018

how to dynamically add and remove the Canada Post autocomplete in Javascript?

it is quite easy to enable the canada post autocomplete, we just need to follow the sample from Canada post autocomplete.

here is the sample code to initialize the Canada post autocomplete to a textbox with id "street-address"

 enableCanadaPostAutoComplete = function () {
        var fields = [
            {
                element: "street-address", field: "Line1"
            },
            {
                element: "street-address2", field: "Line2",
            },
            {
                element: "city", field: "City", mode: pca.fieldMode.PRESERVE
            },
            {
                element: "province", field: "ProvinceCode", mode: pca.fieldMode.POPULATE
            },
            {
                element: "postal", field: "PostalCode", mode: pca.fieldMode.PRESERVE
            },
            { element: "country", field: "CountryIso3", mode: pca.fieldMode.COUNTRY }
        ],
            options = {
                key: sci.CanadaPostKey,
            };

        control= new pca.Address(fields, options);
    }

if you want to remove the Canada post autocomplete feature from the input textbox, then i will show how make it work around

var canadaPostAutoCompleteControl = canadaPostAutoCompleteControl || {};

enableCanadaPostAutoComplete = function () {
        var fields = [
            {
                element: "street-address", field: "Line1"
            },
            {
                element: "street-address2", field: "Line2",
            },
            {
                element: "city", field: "City", mode: pca.fieldMode.PRESERVE
            },
            {
                element: "province", field: "ProvinceCode", mode: pca.fieldMode.POPULATE
            },
            {
                element: "postal", field: "PostalCode", mode: pca.fieldMode.PRESERVE
            },
            { element: "country", field: "CountryIso3", mode: pca.fieldMode.COUNTRY }
        ],
            options = {
                key:  myCanadaPostKey,
            };

        canadaPostAutoCompleteControl = new pca.Address(fields, options);
    }


disableCanadaPostAutoComplete = function () {
        if (canadaPostAutoCompleteControl) {
            canadaPostAutoCompleteControl.destroy();
        }
    }

you can call disableCanadaPostAutoComplete in the click event.

Friday, March 2, 2018

How to fix "Could not load file or assembly or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)" error in web publish deployment in Windows 8?

I had to make a deployment on the new branch which was branching from the original project. it is working fine that i published the web to the server in the original branch. However i encountered an error

"SGEN : error : Could not load file or assembly 'file:///C:\Users\ddeng\Documents\\bin\HiQPdf.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)"



 When i check the folder, the HiQPdf.dll file did exist in the folder. the root cause of this error is that those third party DLL had been locked by Windows 8 due to security concern.

we have to unlock it to allow the publish action to move the dll to the destination folder.

please follow the steps to fix the issue.

1. right click to get properties 



2 in the properties there was a button UNBLOCK, click on the Unlock button and applied the change.




try to rebuild again. you will see your publish go through suceessfully.