Tuesday, July 11, 2017

How to launch a document by clicking a link to the file?

Word:
<a href='ms-word:ofe|u|path/to/web/word/document.docx'>Link to document</a>

Excel:
<a href='ms-excel:ofe|u|path/to/web/word/document.xlsx'>Link to document</a>

Powerpoint
<a href='ms-powerpoint:ofe|u|path/document.pptx'>Link to document</a>

Monday, July 3, 2017

CSOM - Get list items using SPSiteDataQuery


SPList oList = context.GetWebList(LISTNAME);
Guid listGuid = oList.ID;

SPSiteDataQuery dataQuery = new SPSiteDataQuery();
dataQuery.Webs = "<Webs Scope=\"Recursive\">";
SPQuery query = new SPQuery();
query.Query = string.Format("<Where><And><Eq><FieldRef Name='Title' /><Value Type='Text'>{0}</Value></Eq></Where><OrderBy><FieldRef Name='ID'/></OrderBy>", titleString);

dataQuery.Query = query.Query;
dataQuery.Lists = string.Format("<Lists><List ID=\"{0}\" /></Lists>", listGuid);
dataQuery.ViewFields = "<FieldRef Name=\"Title\" Nullable=\"TRUE\"/>";

DataTable dt = GetResults(dataQuery, "TableName");

Sync document library with PC using javascript

EnsureScriptFunc('offline.js', 'TakeOfflineToClientReal', function() {
           TakeOfflineToClientReal(2, 53, 'https://siteUrl/', 1, 101, listGuid, folderUrl);
});

TakeOfflineToClientReal (scope, siteTemplate, siteUrl, listBaseType, listTemplateId, listGuid, folderUrl)

Thursday, May 11, 2017

Email using REST API

var urlTemplate = objInit.webAbsoluteUrl + "/_api/SP.Utilities.Utility.SendEmail";
        $.ajax({
            contentType: 'application/json',
            url: urlTemplate,
            type: "POST",
            data: JSON.stringify({
                'properties': {
                    '__metadata': {
                        'type': 'SP.Utilities.EmailProperties'
                    },
                    'From': from,
                    'To': { 'results': to },
                    'CC': { 'results': cc },
                    'BCC': { 'results': bcc },
                    'Body': "emailBody",
                    'Subject': "emailSubject"
                }
            }),
            headers: {
                "Accept": "application/json;odata=verbose",
                "content-type": "application/json;odata=verbose",
                "X-RequestDigest": jQuery("#__REQUESTDIGEST").val()
            },
            success: function (data) {
                alert('Email Sent Successfully');
            },
            error: function (err) {
                alert('Error in sending email: ' + JSON.stringify(err));
            }
        });

Tuesday, April 18, 2017

Create site collection using CSOM

                string userName = WebConfigurationManager.AppSettings.Get("UserName");
                string password = WebConfigurationManager.AppSettings.Get("Password");
                string domain = WebConfigurationManager.AppSettings.Get("Domain");

                using (var ctx = new ClientContext("http://siteUrl/"))
                {
                    ctx.Credentials = new System.Net.NetworkCredential(userName, password, domain);
                    ctx.RequestTimeout = Timeout.Infinite;

                    var tenant = new Tenant(ctx);
                    var properties = new SiteCreationProperties()
                    {
                        Url = "http://siteUrl/sites/site1",
                        Owner = string.Format("{0}\\{1}",domain,userName),
                        Title = "Test Site",
                        Template = "STS#0"
                    };

                    SpoOperation op = tenant.CreateSite(properties);
                    ctx.Load(op, i => i.IsComplete);
                    ctx.ExecuteQuery();
                }

Monday, March 27, 2017

Get current user image using javascript

siteUrl+ "/_layouts/15/userphoto.aspx?size=M&accountname=" + _spPageContextInfo.userLoginName;

Thursday, January 5, 2017

How to Create an Export to Excel Link on Any List or Library for 2010 and 2013

Generate the below URL for any list / library

SiteURL/_vti_bin/owssvr.dll?CS=109&Using=_layouts/query.iqy&List={List ID}&View={View ID}&CacheControl=1


Ex:

http://SharepointSiteCollection:80/_vti_bin/owssvr.dll?CS=109&Using=_layouts/query.iqy&List={XXXXXXXX-XXXX-XXXX-XXXXXXXXX&View={XXXXXXXX-XXXX-XXXX-XXXXXXXXX}&CacheControl=1


Note : For List ID and View ID, you could get it from List Setting page and View page respectively

How to launch a document by clicking a link to the file?

Word: <a href='ms-word:ofe|u|path/to/web/word/document.docx'>Link to document</a> Excel: <a href='ms-excel:o...