Skip to content

Instantly share code, notes, and snippets.

View garima2510's full-sized avatar

Garima Agrawal garima2510

View GitHub Profile
$ErrorActionPreference = "Stop"
#Name of pfx file that needs to be password protected with extension
$pfxFileName = Read-Host -Prompt 'Input pfx file name'
if($pfxFileName) {
#Replace .\ with actual path where .pfx is stored. Do not include file name
$pfxFilePath = (Get-Item -Path ".\").FullName
@garima2510
garima2510 / RefreshAASModel.ps1
Last active February 21, 2020 06:48
Powershell to asynchronously refresh analysis server model in azure
using namespace System.Net
# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)
# Init defaults
$status = [HttpStatusCode]::BadRequest
$ErrorActionPreference = "STOP"
$RequestBody = $Request.Body
using System;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Table;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
/// <summary>
/// code to delete data from logs table
/// </summary>
/// <param name="numberOfDays">days before which all data should be deleted</param>
@garima2510
garima2510 / DeleteOldTables.cs
Last active August 20, 2019 15:23
Code to delete old storage tables from Azure
using System;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Table;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
/// <summary>
/// delete old metrics table both PT1H and PT1M
/// </summary>
/// <param name="tablepPrefix">WADMetricsPT1HP10DV2S and WADMetricsPT1MP10DV2S</param>
@garima2510
garima2510 / HomeController.cs
Last active July 31, 2019 02:40
Code to invoke MIP SDK for SharePoint files
private void InvokeMIP()
{
//this client id is for Azure AD app and NOT of SharePoint app
private static readonly string clientId = ConfigurationManager.AppSettings["ida:ClientId"];
private static readonly string appName = ConfigurationManager.AppSettings["app:Name"];
private static readonly string appVersion = ConfigurationManager.AppSettings["app:Version"];
private static readonly string mipData = ConfigurationManager.AppSettings["MipData"];
private readonly string mipPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, mipData);
try
{
@garima2510
garima2510 / CustomDbContext.cs
Last active September 16, 2020 04:28
Partial class to override SaveChanges of DbContext and use it for creating audit trail
public partial class CustomDbContext: DbContext
{
public override int SaveChanges()
{
// Get all Added/Deleted/Modified entities (not Unmodified or Detached)
//you can get updated and deleted in same collection. I am doing so for ease of purpose
//getting added entries in different collection to fetch their generated ids and then log them
var addedEntries = ChangeTracker.Entries().Where(e => e.State == EntityState.Added).ToList();
var updatedEntries = ChangeTracker.Entries().Where(e => e.State == EntityState.Modified).ToList();
var deletedEntries = ChangeTracker.Entries().Where(e => e.State == EntityState.Deleted).ToList();
public class HomeController : Controller
{
private static string clientId = ConfigurationManager.AppSettings["ida:ClientId"]; //clientId
private static string appKey = ConfigurationManager.AppSettings["ida:AppKey"]; //clientSecret
private static string aadInstance = ConfigurationManager.AppSettings["ida:AADInstance"]; //https://login.windows.net/{0}
private static string tenant = ConfigurationManager.AppSettings["ida:Tenant"]; //TenantName.onmicrosoft.com
private const string ResourceUri = "https://onenote.com";
public static readonly string Authority = String.Format(CultureInfo.InvariantCulture, aadInstance, tenant);//https://login.windows.net/TenantName.onmicrosoft.com
Uri returnUri = new Uri("https://localhost:44327/Home/ReturnFlow");
@garima2510
garima2510 / CopyDocument.cs
Created October 31, 2014 11:16
ProviderHostedApp - CopyDocument
string filePath = "/TestLibrary/TestDocument.pptx";
var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);
using (var sourceContext = spContext.CreateUserClientContextForSPHost())
{
Microsoft.SharePoint.Client.File sourceFile = sourceContext.Web.GetFileByServerRelativeUrl(filePath);
//file stream will be used to upload in destination library
var fileStream = sourceFile.OpenBinaryStream();
sourceContext.Load(sourceFile, k => k.ServerRelativeUrl, k => k.Name);
sourceContext.ExecuteQuery();
@garima2510
garima2510 / checkmysite.cs
Last active August 29, 2015 14:07
Check If My Site Exists
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.UserProfiles;
using (ClientContext clientContext = new ClientContext("https://tenant.sharepoint.com/"))
{
SecureString passWord = new SecureString();
foreach (char c in "your_password".ToCharArray()) passWord.AppendChar(c);
clientContext.Credentials = new SharePointOnlineCredentials("your_email_id", passWord);
@garima2510
garima2510 / GetMySiteUrl.cs
Last active August 29, 2015 14:07
Get My Site Url
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.UserProfiles;
using (ClientContext clientContext = new ClientContext("https://tenant.sharepoint.com/"))
{
SecureString passWord = new SecureString();
foreach (char c in "your_password".ToCharArray()) passWord.AppendChar(c);
clientContext.Credentials = new SharePointOnlineCredentials("your_email_id", passWord);