Skip to content

Instantly share code, notes, and snippets.

@premsh
premsh / copyRowSameTable
Created May 19, 2014 14:41
Copy row same table MSSQL
DECLARE @Tablename NVARCHAR(255) = 'MyTable'
DECLARE @IdColumn NVARCHAR(255) = 'MyTableId' -- Primarykey-Column, will be ignored
DECLARE @IdToCopyFrom VARCHAR(255) = '33' -- Copy from this ID
DECLARE @ColName NVARCHAR(255)
DECLARE @SQL NVARCHAR(MAX) = ''
DECLARE Table_Cursor CURSOR FOR
SELECT [B].[Name]
FROM SYSOBJECTS AS [A], SYSCOLUMNS AS [B]
using (var client = new HttpClient())
{
var message = new HttpRequestMessage(HttpMethod.Post, url);
message.Headers.Add("Authorization", authKey);
message.Headers.Add("Audit",auditKey);
message.Content = new StringContent(content, new UTF8Encoding(), "application/json");
var response = client.SendAsync(message).Result;
@premsh
premsh / SharePoint_Logger
Last active December 15, 2015 19:59
SharePoint Logging
SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("Name", TraceSeverity.High, EventSeverity.Error), TraceSeverity.Unexpected, "error message", ex.StackTrace);
@premsh
premsh / sharePointdeployment.ps1
Created April 15, 2013 22:04
Farm Solution Deployment PowerShell Command
Add-PSSnappin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$SolutionPackageName = "name.wsp"
$SolutionPackagePath = "projectname\name.wsp"
$solution = Get-SPSolution | where-object {$_.name -eq $SolutionPackageName}
if($solution -ne $null)
{
if($solution.Deployed -eq $true)
@premsh
premsh / udpateSharePointSolution.ps1
Created April 15, 2013 22:11
Update SharePoint Solution
$solutionPackageName = "name.wsp"
$SolutoinPackagePath = "path\name.wsp"
Update-SPSolution -Identity $SolutionPackageName -LiteralPath $SolutionPackagePath -Local -GACDeployment
@premsh
premsh / sp2013_SampleREST
Created May 1, 2013 00:23
Sample REST api call for SharePoint-Hosted app
$.ajax(
{
url: _spPageContextInfo.webServerRelativeUrl + "/_api/web/currentuser",
type: "GET",
headers: {
"accept": "application/json;odata=verbose",
},
success: function (data) {
$("#message").text('Hello ' + data.d.Title);
},
@premsh
premsh / CreateSharePointGroup
Created May 16, 2013 22:40
create sharepoint group upon feature activation
const string groupName = "CandidateSigned";
// Creates group
public static void CreateCandidateSignedPermissionGroup(SPWeb web, string groupName, string groupDescription)
{
SPUserCollection users = web.AllUsers;
SPUser owner = web.SiteAdministrators[0];
SPMember member = web.SiteAdministrators[0];
SPGroupCollection groups = web.Groups;
groups.Add(groupName, member, owner, groupDescription);
@premsh
premsh / gist:5799268
Created June 17, 2013 18:48
Proxy Web Service
[WebService(Namespace = "Foo")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class GetData : System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public string GetInfo()
{
@premsh
premsh / ajaxCall
Created June 24, 2013 22:45
normal AJAX call to WCF
$(document).ready(function () {
$.ajax({
type: 'GET',
url: 'http://localhost:63751/Service1.svc/json/4',
dataType: 'json',
crossDomain: true,
async: true,
success: function (data) {
jsonData = data;
},
@premsh
premsh / allowcrossdomainrequest.cs
Created June 25, 2013 02:50
Cross domain requests for WCF services
protected void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
{
HttpContext.Current.Response.AddHeader("Cache-Control", "no-cache");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept, TenantId"); // TenantId could be anything
HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
HttpContext.Current.Response.End();