Tuesday, August 13, 2019

Upload zip file to azure blob storage



    CloudStorageAccount storageAccount =   CloudStorageAccount.Parse("ConnectionString");
                // Create the blob client.
                CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

                // Retrieve reference to a previously created container.
                CloudBlobContainer container = blobClient.GetContainerReference("Container Name");

                FileInfo zipFile = new FileInfo(@"C:\Documents\myfiles.zip");
                // Retrieve reference to a blob named "myblob".

                CloudBlockBlob blockBlob = container.GetBlockBlobReference(zipFile.Name);
                // Upload the zip and store it in the blob
                using (FileStream fs = zipFile.OpenRead())
                    blockBlob.UploadFromStream(fs);

Thursday, November 29, 2018

Check if the folder or file exists in Sharepoint C# CSOM

                                  var url = "/sites/sitecol/DocLib/FolderName;
                                  try
                                {
                                    var file = ctx.Web.GetFileByServerRelativeUrl(url);
                                    ctx.Load(file);
                                    ctx.ExecuteQuery();
                                 }
                                catch (ServerException ex) {

                                       if (ex.ServerErrorTypeName == "System.IO.FileNotFoundException") {
                                                                      }
                                           }

Error: Could not create SSL/TLS Secure channel

Solution include


ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;


We have to make sure that the server and the client have common protocol support.




Saturday, September 23, 2017

Access SharePoint list across domain using CSOM SharePoint 2013

var context;
var hostweburl;
var appweburl;
var appContextSite;
var list;
var web;

 
(function () {

$(document).ready(function () {
        SP.SOD.executeFunc('sp.js', 'SP.ClientContext', getUrl);
    });

   function getUrl () {
        hostweburl = getQueryStringParameter("SPHostUrl");
        appweburl = getQueryStringParameter("SPAppWebUrl");
        hostweburl = decodeURIComponent(hostweburl);
        appweburl = decodeURIComponent(appweburl);

alert("hostweburl: " + hostweburl);
alert("appweburl: " + appweburl);

    var scriptbase = hostweburl + "/_layouts/15/";
                $.getScript(scriptbase + "SP.Runtime.js",
                    function () {
                        $.getScript(scriptbase + "SP.js",
                        function () { $.getScript(scriptbase + "SP.RequestExecutor.js", execOperation); }
                        );
                    }
                );
            event.preventDefault();


function execOperation() {
        context = new SP.ClientContext(appweburl);
        var factory =
            new SP.ProxyWebRequestExecutorFactory(
                appweburl
            );
        context.set_webRequestExecutorFactory(factory);
        appContextSite = new SP.AppContextSite(context, hostweburl);
        web = appContextSite.get_web();
        context.load(web);

        list = web.get_lists().getByTitle("TestList");
        context.load(list);
        context.executeQueryAsync(onSuccess, onFail);
        }
        function onSuccess() {
              alert("List loaded Successfully");
        }

        // This function is executed if the above call fails
        function onFail(sender, args) {
               alert( args.get_message());
        }
    }
function getQueryStringParameter(paramToRetrieve) {
                var params =
                    document.URL.split("?")[1].split("&");
                for (var i = 0; i < params.length; i = i + 1) {
                    var singleParam = params[i].split("=");
                    if (singleParam[0] == paramToRetrieve)
                        return singleParam[1];
                }
            }
})();

Tuesday, June 2, 2015

SharePoint 2013 - Create an App to get lists using CSOM

'use strict';

var context = SP.ClientContext.get_current();
var user = context.get_web().get_currentUser();
var web = context.get_web();
var list = web.get_lists();

(function () {
    // This code runs when the DOM is ready and creates a context object which is
    // needed to use the SharePoint object model

    $(document).ready(function () {
        getListCount();
    });

    // This function prepares, loads, and then executes a SharePoint query to get
    // the current users information

  function getListCount() {
context.load(web);
context.load(list);
        context.executeQueryAsync(onGetListCountSuccess, onGetListCountFail);
    }

    // This function is executed if the above call is successful
    // It replaces the contents of the 'message' element with the user name

    function onGetListCountSuccess() {

    var ernumerator = list.getEnumerator();
  while(ernumerator.moveNext())
  {
  var listname = ernumerator.get_current();
      alert(listname.get_title());
  }

  $('#message').text('Hello ' +list.get_count());
    }

    // This function is executed if the above call fails

    function onGetListCountFail(sender, args) {
        alert('Failed to get list count. Error:' + args.get_message());
    }
})();

Sunday, April 5, 2015

Create your first app free in cloud Office 365 SharePoint 2013

Microsoft has provided an online free developer environment for creating Apps in SharePoint 2013.

In order to create an app below are the keys things we need to keep in mind

1) The site should be created using Developer site template.

2) When the developer site is created we would need to browse to SharePoint Store to add the NAPA tool as an app.

Start here.

https://msdn.microsoft.com/en-us/library/office/fp179924.aspx