Skip to content

Instantly share code, notes, and snippets.

View vman's full-sized avatar
👨‍💻

Vardhaman Deshpande vman

👨‍💻
View GitHub Profile
@vman
vman / pageHtml
Created April 27, 2011 18:14
Get HTML from page in SharePoint Client Obeject Model
ClientContext clientcontext = new ClientContext(sitecollection);
clientcontext.Credentials = Credentials;
var page = Microsoft.SharePoint.Client.File.OpenBinaryDirect(clientcontext, "/Sites/Vard/SitePages/Home.aspx");
StreamReader reader = new StreamReader(page.Stream);
string pageHTML = reader.ReadToEnd();
@vman
vman / customactioncss.xml
Created January 21, 2012 07:59
Custom Action for CSS
<CustomAction Location="ScriptLink" ScriptBlock="document.write('&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;/SiteAssets/Styles/mystyles.css&quot;&gt;&lt;/' + 'link&gt;');" Sequence="5000" />
@vman
vman / customactioncss.cs
Created January 21, 2012 08:02
Custom Action for CSS
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
//Add the Css to the current Web
SPSite site = properties.Feature.Parent as SPSite;
SPWeb web = site.OpenWeb();
if (web.ServerRelativeUrl == "/")
{
web.AlternateCssUrl = web.ServerRelativeUrl + "SiteAssets/Styles/mystyles.css";
}
else
@vman
vman / loadCOM.coffee
Created January 23, 2012 18:31
JSCOM loadCOM in CS
loadCOM = () ->
context = new SP.ClientContext.get_current()
web = context.get_web()
context.load web
context.executeQueryAsync ->
#Success Callback
alert web.get_title()
, (sender,args)->
#Failure CallBack
@vman
vman / jQueryCoffee.coffee
Created January 25, 2012 14:11
coffeescriptjquery
#Create a new Button
myButton = $("<input id='cfLink' type='button' value='Click Me'/>")
#Assign a click function to the button which sends the button itself as the first parameter
myButton.click -> linkClicked (this)
#Push myLink into the DOM after the ribbon container.
$("#s4-ribbonrow").after myButton
#When this function is called, alert the value attribute of the button.
linkClicked = (button) ->
@vman
vman / generalcoffee.coffee
Created January 25, 2012 14:13
generalcoffee
#The initCoffee function has one required paramter (firstname) and one optional paramter (lastname) whose default valu has been provided.
initCoffee = (firstname, lastname="deshpande") ->
#You can include wildcards whithin a string so you dont have to concatenate various strings together.
alert "Hi #{firstname} #{lastname}! Welcome to CoffeeScript Demo on SharePoint"
#Call the initCoffee function with passing only one parametre.
initCoffee("vardhaman")
@vman
vman / additem.coffee
Created January 25, 2012 14:16
additemcoffee
AddItem = () ->
context = new SP.ClientContext.get_current()
list = context.get_web().get_lists().getByTitle "CoffeeList"
listItemCreateInfo = new SP.ListItemCreationInformation
listItem = list.addItem listItemCreateInfo
listItem.set_item "Title","Mocha"
listItem.update();
context.executeQueryAsync ->
#Success Callback
alert "Item Added"
@vman
vman / updateitem.coffee
Created January 25, 2012 14:18
updatecoffee
UpdateItem = () ->
context = new SP.ClientContext.get_current()
list = context.get_web().get_lists().getByTitle "CoffeeList"
listItem = list.getItemById 1
listItem.set_item "Title", "Latte"
listItem.update();
context.executeQueryAsync ->
#Success Callback
alert "Item Updated"
@vman
vman / deleteitem.coffee
Created January 25, 2012 14:19
deletecoffee
DeleteItem = () ->
context = new SP.ClientContext.get_current()
list = context.get_web().get_lists().getByTitle "CoffeeList"
listItem = list.getItemById 1
listItem.deleteObject();
context.executeQueryAsync ->
#Success Callback
alert "Item Deleted"
, (sender,args)->
@vman
vman / getitems.coffee
Created January 25, 2012 14:21
getitemscoffee
GetItems = () ->
context = new SP.ClientContext.get_current()
list = context.get_web().get_lists().getByTitle "CoffeeList"
listItems = list.getItems ''
context.load listItems
context.executeQueryAsync ->
#Success CallBack
itemEnum = listItems.getEnumerator()
alert itemEnum.get_current().get_item "Title" while itemEnum.moveNext()