Showing posts with label sharepoint-2010. Show all posts
Showing posts with label sharepoint-2010. Show all posts

Tuesday, 11 August 2020

How to search documents using SPServices and SharePoint Search?

 

var searchtext ="string to be searched";

SharePoint 2010:

var queryText = "<QueryPacket xmlns='urn:Microsoft.Search.Query' Revision='1000'>";

queryText += "<Query>";

queryText += "<Context>";

queryText += "<QueryText language='en-US' type='MSSQLFT'>";

queryText += "SELECT SpSiteUrl, Title, Path, Description, HitHighlightedSummary, IsDocument";

queryText += "FROM Scope() WHERE FREETEXT(DEFAULTPROPERTIES, '";

queryText += searchtext;

queryText += "')And CONTAINS(Path, 'https://server/sites/site/subsite/library')";

queryText += "ORDER BY \"Rank\" DESC";

queryText += "</QueryText>";

queryText += "</Context>";

queryText += "<Range><Count>5000</Count></Range>";

queryText += "</Query>";

queryText += "</QueryPacket>";


SharePoint Online:

var queryText = "<QueryPacket xmlns='urn:Microsoft.Search.Query' Revision='1000'>"

queryText += "<Query>"

queryText += "<Range><Count>500</Count></Range>";

queryText += "<Context>"

queryText += "<QueryText language='en-US' type='STRING'>"

queryText += searchtext;

queryText += " Site:https://server/sites/site/subsite/library/";

queryText += "</QueryText>"

queryText += "</Context>"

queryText += "</Query>"

queryText += "</QueryPacket>";


//declare required variables


$().SPServices({//sart service call

    operation: "Query",

    queryXml: queryText,

    async: false,

    completefunc: function (xData, Status) {

$(xData.responseXML).find('CopyResult').attr('ErrorMessage'));

        $(xData.responseXML).find("QueryResult").each(function () {

            var x = $(this).text();

            $(x).find("Document").each(function () {

                url = $("Action>LinkUrl", $(this)).text();

                if ((url.indexOf("site/subsite/library") > 0) && 

                    ((url.indexOf("aspx")) == -1)) {

title = $("Title", $(this)).text();

size = $("Action>LinkUrl", $(this)).attr('size');

ext = $("Action>LinkUrl", $(this)).attr('fileExt');

desc = $("Description", $(this)).text();

//clear/reset variables

                }

            });

        });


    }

});//end service call

Friday, 29 September 2017

SPServices : How to update SharePoint list item?


$(document).ready(updateListItem(12,"Next3"));

function updateListItem(itmeID,newTitle) {
 
    $().SPServices({
        //webURL: "https://domain/site_coll/site/",
        operation: "UpdateListItems",
        valuepairs: [["Title", newTitle]],
        async: false,
        listName: "Test List",
        ID: itmeID,
        completefunc: success_updateListItem
    });
 
}

function success_updateListItem(xData, status) {
alert(status);
}

Thursday, 28 September 2017

SPServices: How to fetch filtered SharePoint list items?


$(document).ready(getListItems);

function getListItems() {
 
    $().SPServices({
        //webURL: "https://domain/sites/site_collection/site",
        operation: "GetListItems",
        async: false,
        listName: "Test List",
        CAMLViewFields: "<ViewFields Properties='True' />",
        CAMLQuery: "<Query><Where><Eq><FieldRef Name='Title' /><Value Type='Text'>YourValueHere</Value></Eq></Where></Query>",
        completefunc: success_getListItems
    });
 
}

function success_getListItems(xData, status) {
$(xData.responseXML).SPFilterNode("z:row").each(function () {
                var liHtml = "<li>" + $(this).attr("ows_Title") + "</li>";
                $("#tasksUL").append(liHtml);
            });
}

SPServices: How to fetch SharePoint list items with all fields?



$(document).ready(getListItems);

function getListItems() {
    $().SPServices({
        //webURL: "https://domain/sites/site_collection/site",
        operation: "GetListItems",
        async: false,
        listName: "Test List",
        CAMLViewFields: "<ViewFields Properties='True' />",
        completefunc: success_getListItems
    });
}

function success_getListItems(xData, status) {
$(xData.responseXML).SPFilterNode("z:row").each(function () {
                var liHtml = "<li>" + $(this).attr("ows_Title") + "</li>";
                $("#tasksUL").append(liHtml);
            });
}

Friday, 15 September 2017

How to create week wise list views in SharePoint?


To create week wise list view in SharePoint list follow the following steps.

Step 1. Create a calculated column named 'WeekStart' of type Date with the following formula:

=IF(TEXT(WEEKDAY([Created]),"ddd")="Mon",[Created],(IF(TEXT(WEEKDAY([Created]-1),"ddd")="Mon",[Created]-1,(IF(TEXT(WEEKDAY([Created]-2),"ddd")="Mon",[Created]-2,(IF(TEXT(WEEKDAY([Created]-3),"ddd")="Mon",[Created]-3,(IF(TEXT(WEEKDAY([Created]-4),"ddd")="Mon",[Created]-4,(IF(TEXT(WEEKDAY([Created]-5),"ddd")="Mon",[Created]-5,[Created]-6))))))

Step 2. Create a calculated column named 'WeekEnd' of type Date with the following formula:

=IF(TEXT(WEEKDAY([Created]),"ddd")="Sun",[Created],(IF(TEXT(WEEKDAY([Created]+1),"ddd")="Sun",[Created]+1,(IF(TEXT(WEEKDAY([Created]+2),"ddd")="Sun",[Created]+2,(IF(TEXT(WEEKDAY([Created]+3),"ddd")="Sun",[Created]+3,(IF(TEXT(WEEKDAY([Created]+4),"ddd")="Sun",[Created]+4,(IF(TEXT(WEEKDAY([Created]+5),"ddd")="Sun",[Created]+5,[Created]+6))))))


Step 3. Create a new view to filter the items based on the following criteria:

WeekStart < [Today] < WeekEnd.


Following can be used to create a previous week view: WeekStart < [Today]-7 < WeekEnd. Similarly following for next week WeekStart < [Today]+7 < WeekEnd.




Thursday, 16 March 2017

SharePoint Designer: What does a workflow lookup returns when the item is not found?


Item not found returns: ?????

Unassigned workflow variable returns: ****

Note: If you will look for ID of an item that does not exists then the variable will be assigned to 0.


Wednesday, 17 August 2016

How to remove multiple SharePoint user permission without getting following error message: "You have chosen to delete too many groups at once. Select fewer groups and try again".


SharePoint doesn't allow to delete all 1000s of users at once. But, we can delete 400 at a time. That again is quite tedious - selecting 400 hundred check-boxes manually.

We can reduce the effort for selecting checkboxes manually by using the browser's developer tool.

Press F12 on your browser to open the developer tool.

Go to console and execute the following to select only 400 users at a time:

(function() {
    var aa = document.querySelectorAll("input[type=checkbox]");
    for (var i = 1; i < 400; i++){
        aa[i].checked = true;
    }
})()



Note: Loop is executed from the 2nd index to avoid 'select all' checkbox.


-----------------------------------------OR---------------------------------------------------

Use the following CSOM code:

public static void RemoveSitePermissions()
        {
            ClientContext ctxSource = new ClientContext("https://domain.com/sites/siteColl/siteName/");
            string decryptedPwd = "password";
            foreach (char c in decryptedPwd)
            {
                securePassword.AppendChar(c);
            }
            ctxSource.Credentials = new SharePointOnlineCredentials("user@domain.com", securePassword);
            Web webSource = ctxSource.Web;
            ctxSource.Load(webSource);
            UserCollection userColl = webSource.SiteUsers;
            ctxSource.Load(userColl);
            ctxSource.ExecuteQuery();

            foreach (User user in userColl.ToList())
            {
                try
                {
                    userColl.Remove(user);
                    ctxSource.ExecuteQuery();
                    Console.Write(".");
                 
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

Thursday, 5 February 2015

How to get all SharePoint Web Applications from SP Farm programmatically using C# ?

Here is a way to get all SharePoint Web Applications in a SP Farm:

public ListItemCollection GetAllWebApplicationsInSPFarm()
{
ddlDataSource = new ListItemCollection();
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPServiceCollection services = SPFarm.Local.Services;
foreach (SPService curService in services)
{
if (curService is SPWebService)
{
webService = (SPWebService)curService;
if (curService.TypeName.Equals("Microsoft SharePoint Foundation Web Application"))
{
webService = (SPWebService)curService;
SPWebApplicationCollection webApplications = webService.WebApplications;
foreach (SPWebApplication webApplication in webApplications)
{
if (webApplication != null)
{
//Now you have the required object i.e. webApplication. You can use it like this:
//string webApp = webApplication.AlternateUrls[0].Collection.Name.ToString();
//Write your code here…    
}
}
}
}
}
});
}

How to open SharePoint application page in modal dialog (popup) using c#?

C# Code:
void OpenApplicationPageAsPopup(){
string strWebUrl = SPContext.Current.Web.Url;
string strPageURL = strWebUrl + "/_layouts/MyLayoutFolder/MyPage.aspx";
System.Web.UI.ScriptManager.RegisterStartupScript(this, this.GetType(), ClientID, "ExecuteOrDelayUntilScriptLoaded(openModelDialogPopup('" + strPageURL + "'), \"SP.js\");", true);

}
JavaScript Code:
function openModelDialogPopup(strPageURL ) {

    var dialogOptions = {
        title: "This is Modal Dialog", //Popup title.
        url: strPageURL, 
        width: 600, // Width of the dialog.
        height: 400
    };
    SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', dialogOptions);
    return false;
}