Monday, February 26, 2018

Run InstallShield Setup (InstallScript MSI) with logging

Setup.exe /debuglog"C:\PathToLog\setupexe.log" /V"/L*v c:\PathToLog\SetupMSI.log"

Thursday, February 22, 2018

Async Await support for Console Applications

Nito.AsyncEx is the library which can be used to add support for Console application. (not limited to console application.)
Add the nuget package - Nite.AsyncEx

And then call your function as

AsyncContext.Run(() => ExecuteMethodAsync());

private static async Task ExecuteMethodAsync()
{
//do something
}

Happy Coding!

Thursday, February 15, 2018

Sample Code to open PDF File in Browser instead of download



public HttpResponseMessage Get(int id)
{
try
{
string filename = "File.pdf";
string filepath = System.Web.HttpContext.Current.Server.MapPath("~") + "/" + filename;
byte[] filedata = System.IO.File.ReadAllBytes(filepath);
string contentType = MimeMapping.GetMimeMapping(filepath);

HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
result.Content = new ByteArrayContent(filedata); ;
result.Content.Headers.ContentType = new MediaTypeHeaderValue(MimeMapping.GetMimeMapping(filepath));
var cd = new System.Net.Mime.ContentDisposition
{
FileName = filename,
Inline = true,
};

HttpContext.Current.Response.Headers.Add("Content-Disposition", cd.ToString());
return result;

}
catch (Exception)
{
throw new HttpResponseException(HttpStatusCode.InternalServerError);
}
}

Converting a guest user to member in Azure AD

To convert a guest user into a member in Azure Ad run the following command.


Connect-MsolService
login with Global admin of the AD in which guest user exists.

Get-MsolUser -UserPrincipalName hpatel#EXT#@yourdomain.onmicrosoft.com -UserType Member

This should convert the user to member.
hpatel#EXT#@yourdomain.onmicrosoft.com is the guest user. remember Microsoft adds #EXT# to the email. so if you get error that says that user not found, run the following command and validate the upn.
Get-MsolUser --UnlicensedUserOnly