Thursday, May 30, 2013

Hide "Shared With" option for a list or library in SharePoint 2013

Hi Friends,

There is a feature in SharePoint 2013 that allows users to view "To whom the item has been shared with" for a list or library. If you want this information to be secret, you will need to configure some settings in user permissions.

Lets say that you have a document in document library as shown below.

If you click the ellipsis button with three dots (...)  as shown in above figure, you can also see information like with whom it has been shared with. If you want to hide this information with some user groups, for example lets say Read Only users, then you can follow these simple steps.

1. Log in to the site with a user in Site Owner group.
2. Go to Site Settings.
3. Go to Site Permissions.
4. Click Permission Levels on the ribbon.
     
5. Click the Read Link.
6. Uncheck Browse User Information option and  Submit.

Now, if you log in to the site with any user with Read Only permission and click the ellipsis for that particular item, you won't be able to see with whom it has been shared.


Cheers



Read only users unable to create alerts in SharePoint 2013

Hi friends, I was stuck in a problem where a read only user in SharePoint is able to read and view all the items in a list and library but unable to create an alert for himself/herself.


You can see the Alert Me button is enabled. But when you try to create one for yourself, you will be surprised to see following message.


What? The site hasn't been shared with you? If the site has not been shared with you, then how can you view the library and view item? Well,  I tried to do the same thing in my SharePoint 2010 environment. And it did allowed me to create an alert for Read Only user without any hassle. You may wonder if there is something wrong with SharePoint 2013 as I did. After doing some hit and trials with User Permissions, I was able to figure it out.

Lets go this way.

  1.  Login to the site with another user with higher privilege, i.e. Site Owner.
  2. Go to Site Settings.
  3. Go to Site Permissions.
  4. Click Permission Levels on the ribbon.
  5. Click the Read Link.
  6. Check Browse User Information and  Submit. 

    Now, log in back to your site with previous read only users. If you are using separate browsers for two uses, refresh the browser. You should be able to create your alert without any hassle. 






Wednesday, May 22, 2013

Parsing XML using AJAX

Hi friends,

Lets say we have an XML file named "data.xml" as shown below.


<?xml version="1.0" encoding="utf-8" ?>
<speakers>
  <speaker>
    <name>LaVonne L. LaRue</name>
    <shortname>LaVonne_LaRue</shortname>
    <reknown>Chicago, IL</reknown>
    <bio>LaVonne's giant-sized paintings all around Chicago tell the story of love, nature, and conversation - themes that are central to her heart. LaVonne will share her love and skill of graffiti art on Monday's schedule, as she starts the paintings of a 20-foot high wall in the Rousseau Room of Hotel Contempo in front of a standing-room only audience in Art in Unexpected Places.</bio>
  </speaker>
  <speaker>
    <name>Samuel Deji Eniojukan</name>
    <shortname>Sam</shortname>
    <reknown>Atlanta, GA</reknown>
    <bio>Sam is expert sharepoint architecture.</bio>
  </speaker>
  <speaker>
    <name>Suraj Shrestha</name>
    <shortname>Suraj</shortname>
    <reknown>Boston, MA</reknown>
    <bio>Suraj is expert .NET programmer.</bio>
  </speaker>
  <speaker>
    <name>Hari Paudel</name>
    <shortname>Honey</shortname>
    <reknown>Jackson Heights, NY</reknown>
    <bio>Hari is expert MVC developer.</bio>
  </speaker>
  <speaker>
    <name>Merin Nakarmi</name>
    <shortname>Merin</shortname>
    <reknown>Atlanta, GA</reknown>
    <bio>Merin is expert SharePoint and .NET Developer/Architecture.</bio>
  </speaker>
  <speaker>
    <name>Tchelen Lilian Costa Nakarmi</name>
    <shortname>Tchelen</shortname>
    <reknown>Manaus, AM, Brazil</reknown>
    <bio>Tchelen is sweet clarinest girl.</bio>
  </speaker>
</speakers>

And we have a html file named index.html as shown below.

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title>JavaScript Ajax</title>
</head>
<body>
    <h1>AJAX page</h1>
    <div id="speakers">
    </div>
    <script src="script.js" type="text/javascript">
    </script>
</body>
</html> 

Now, we want to display the contents of the XML data file to a html page. We only want to display the list of name of speakers in the div with id "speakers". For this, we have an external JavaScript file named "script.js" as shown below.


var request;

if (window.XMLHttpRequest) {
    request = new XMLHttpRequest();
}
else {
    request = new ActiveXObject("Microsoft.XMLHTTP");
}

request.open('GET', 'data.xml');

request.onreadystatechange = function () {
    if((request.readyState === 4) && (request.status === 200))
    {      
        var items = request.responseXML.getElementsByTagName('name');
        var output = '<ul>';
        for (var i = 0; i < items.length; i++) {
            output += '<li>' + items[i].firstChild.nodeValue + '</li>';
        }
        output += '</ul>';

        document.getElementById('update').innerHTML = output;
    }
}

request.send();


The output of the  html file would look like


Tuesday, May 21, 2013

Just for myself - SharePoint

Site: Permanent
Workspace: Temporary / Disposable

Document Workspace
  • Similar to Team Site
  • Complex Documents e.g. Annual Report
  • Disposable Resources - used temporarily for e.g. a week or month
Meeting Workspace
  • Agenda
  • List of Attendees
  • Objectives
  • Document Library

Monday, May 20, 2013

Just for myself - JavaScript and Ajax

  1. XMLHttpRequest Object  (XHR)
XMLHttpRequest object is used to exchange data with a server behind the scenes.

With XHR we can
  1. Update a web page without reloading the page.
  2. Request a data from a server after the page has loaded.
  3. Receive data from a server after the page has loaded.
  4. Send data to a server in background
Remember: Update, Request, Receive, Send

To find more about XMLHttpRequest, visit  XMLHttpRequest


  • A synchronous XHR example  : The code snippet below illustrates synchronous XHR call. It reads text from a text file named 'data.txt' and presents in the browser. 
    var request = new XMLHttpRequest();
    request.open('GET', 'data.txt', false);
    request.send();
    console.log(request);
    document.writeln(request.responseText);
  • Asynchronous XHR example: The code snippet below illustrates asynchronous XHR call. It reaqds text from a text file named 'data.txt' and presents in the browser. It also takes in consideration the browser type, e.g. it uses XHR request for browsers like Safari, Chrome, Firefox etc and uses ActiveX for Internet explorer.
var request;
/*
If the browser API has XHR object, then set request variable to new XHR object.. for Safari, FireFox, Chrmoe
*/
if (window.XMLHttpRequest) {
    request = new XMLHttpRequest();
}
else request = new ActiveXObject("Microsoft.XMLHTTP");     // else... for IE
// This makes the script compatible to all browsers
request.open('GET', 'data.txt');  // by default, third parameter is true
request.onreadystatechange = function () {
    if( (request.readyState === 4) && (request.status === 200))
    {
        console.log(request);
        document.writeln(request.responseText);
    }
}
request.send();
Both of the request example above simply writes to a console of a browser.
But we can do the same to modify any part of a web element.


  • getElementById:
    Lets say we have a div element as shown below
    <div id = "heading">
    we can use following DOM command to replace its content as document.getElementById(heading).innerHTML = request.responseText
  • getElementsByTagName:
    Lets say we have some collection of elements, e.g. unordered list as shown below

    <ul>
         <li></li>
         <li></li>
         <li></li>
         <li></li>
         <li></li>
    </ul>


    And we only want to update the third list item, then we can achieve it as shown under.

    var result = document.getElementsByTagName("li");
    result[2].innerHTML = request.responseText



Change URL of the emails send in a Document Library Alert

Hi friends,

If we are subscribed to alert on any SharePoint list or library, we get email notifications along with link to the list or library.
Lets assume the following scenario
Internal Web Application URLhttp://sp-realm/
Public web application URLhttps://access.sharepointrealm.com
Document LibraryResults
Internal URL of Document Libraryhttp://sp-realm/Results

When we create an alert for this library, we get email with the internal link to this document library by default.
If we want to associate public URL with this library, all we have to do is change Alternate Access Mapping and provide public URL in place of Default Zone for that particular web application.

Good Luck !

Balanced Parenthesis Algorithm using Recursive Function

Hi Friends,

Few days ago, I was asked to write a Parenthesis Balancing algorithm as a small test by one of the hiring company. I did it on time and have thought to share it with you guys.

The question goes as under.

Write a function which verifies parenthesis are balanced in a string. Each open parenthesis should have a corresponding close parenthesis and they should correspond correctly.

For example, the function should return true for the following strings:

  • (if (any? y) sum (/1 y))   
  • I said (it's not (yet) complete). (she didn't listen)
The function should return false for the following strings: 
  • :-)
  • ())(
Optional Bonus: Implement the solution as a recursive function with no mutation / side effects. 

Besides the question asking for only the small parenthesis, this program can work on any kind of parenthesis like  
i. < , >
ii. { , }
iii. [ , ]

All you have to do is provide the type of parenthesis as a second and third string parameter to the function. 

Here goes the code: 



private static bool Balanced(string input, string openParenthesis, string closedParenthesis)
        {
            
            try
            {
                if (input.Length > 0)
                {
                    //Obtain first character
                    string firstString = input.Substring(0, 1);

                    //Check if it is open parenthesis
                    //If it is open parenthesis push it to stack
                    //If it is closed parenthesis pop it
                    if (firstString == openParenthesis)
                        stack.Push(firstString);
                    else if (firstString == closedParenthesis)
                        stack.Pop();

                    //In next iteration, chop off first string so that it can iterate recursively through rest of the string
                    input = input.Substring(1, input.Length - 1);
                   Balanced(input, openParenthesis, closedParenthesis);   //this call makes the function recursive
                }

                if (stack.Count == 0 && !exception)
                    isBalanced = true;
            }
            catch (Exception ex)
            {
                exception = true;
            }

            return isBalanced;
        }


Lets call this function to prove the test cases provided by the question:

  1. Balanced("(if (any? y) sum (/1 y))", "(",  ")") 
  2. Balanced("I said (it's not (yet) complete). (she didn't listen)", "(",  ")") 
  3. Balanced(":-)", "(",  ")") 
  4. Balanced("())(", "(",  ")")  
Output:
  1. true
  2. true
  3. false
  4. false

   Good Luck