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

Tuesday, May 14, 2013

Send a test email from SharePoint


Hi Friends,

You might be working with email related activities in SharePoint like workflows or alerts in lists and libraries but before that you need to be sure that SharePoint is sending email. You can check it in numerous ways but be sure that Outgoing Email settings is configured properly in Central Administration Site.

Once you are pretty sure that Outgoing Email settings is properly configured it, you can test it on many ways : like adding users to a new SharePoint group. You can also check it via a power shell script as shown below.

_________________________________________________________________________________
$email = "merin@sprealm.com"
$subject = "Life is good"
$body = "Life is good. Be happy."

$site = New-Object Microsoft.SharePoint.SPSite "http://sprealm:5050"
$web = $site.OpenWeb()
[Microsoft.SharePoint.Utilities.SPUtility]::SendEmail($web,0,0,$email,$subject,$body)
_________________________________________________________________________________

Copy the above script in a note pad and save it in a drive with some names like SendEmail.ps1
Then run the script.
Email sent successfully returns true whereas failure returns false.

// A True or False will confirm the message has been sent or not

Reference:http://jeffreypaarhuis.com/2013/02/12/send-test-email-from-sharepoint/

Monday, May 13, 2013

Accessing Objects and Arrays in JavaScript


Hi friends, I have illustrated the way of accessing an object and array in JavaScript using for loop.

We have an object variable called "info"


 var info = {
            "full_name": "Tchelen Lilian Costa Nakarmi",
            "title": "Staff Author",
            "links": [
                { "blog": "http://tchelennakarmi.blogspot.com" },
                { "facebook": "http://facebook.com" },
                { "google": "www.google.com" },
                { "twitter": "http://twitter.com/" },
                { "youtube": "http://www.youtube.com/" }
                ]
        };

It has three properties as shown below.
  1. full_name:  is an object
  2. title: is an object
  3. links: an array of object
We use indexed for loop to traverse through properties of "info" object 
 for (var i = 0; i < info.links.length; i++) {
................................
}
We use iterative for loop to traverse through properties of objects inside "links" array.
for (key in info.links[i]) {
...................................
}

The traversed items, viz. key value pair of object is appended to a string called output in a form of ordered list item. And we finally assign this output string to the innerHTML of the order list. 

Below is the full code and output. 

_________________________________________________________________________________

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title>Accessing Objects</title>
</head>
<body>
    <h2>Links</h2>

    <ol id="links">

    </ol>

    <script>
        var info = {
            "full_name": "Ray Villalobos",
            "title": "Staff Author",
            "links": [
                { "blog": "http://iviewsource.com" },
                { "facebook": "http://facebook.com/iviewsource" },
                { "podcast": "http://feeds.feedburner.com/authoredcontent" },
                { "twitter": "http://twitter.com/planetoftheweb" },
                { "youtube": "http://www.youtube.com/planetoftheweb" }
                ]
        };

        var output = '';

        for (var i = 0; i < info.links.length; i++) {
            for (key in info.links[i]) {
                if (info.links[i].hasOwnProperty(key)) {
                    output += '<li>' +
                        '<a href="' + info.links[i][key] + '">' + key + '</a>' +
                        '</li>';
                }
            }   //for each object
        }       //for each array

        var update = document.getElementById('links');
        update.innerHTML = output;
    </script>

</body>
</html>
________________________________________________________________________________


A simple table in Windows Store App

Hi friends, a table or datagrid is deprecated in Windows 8 App but I desperately needed that in my app. The GridView control in Windows App does not have notion of Rows or Columns and neither does a ListView.

However I have created a simple table using a ListView and have hardcoded the List Items. Will be doing it dynamically soon.

Here goes my XAML code.

<ListView Grid.Row="0" HorizontalAlignment="Center" Width="300" Margin="0,20,0,0 ">
            <ListViewItem>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Width="150">Apple</TextBlock>
                    <TextBlock>100</TextBlock>
                </StackPanel>
            </ListViewItem>
            <ListViewItem>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Width="150">Banana</TextBlock>
                    <TextBlock>2000</TextBlock>
                </StackPanel>
            </ListViewItem>
            <ListViewItem>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Width="150">Oranges</TextBlock>
                    <TextBlock>1500</TextBlock>
                </StackPanel>
            </ListViewItem>           
        </ListView>

And here is how it looks like.

Shrink a volume in Windows Server 2012


Shrink a volume in Windows Server 2012

Hi friends, if you are wondering that you can only Extend the volume in Windows Server 2012 but you did not see an option to Shrink the volume, please follow these simple steps.

1. Click Server Manager console at the bottom left of the screen.
2. In Server Manager console, click All Servers. If you see your server, right click the server name and click
    computer management as shown below.

3. Click Disk Management under Storage menu item as shown below. Select your disk and right click and
    click Shrink Volume.
 4. Now you know what to do.

Thanks

Start Menu on Windows 8 and Windows Server 2012


Hi friends,

If you are annoyed with the absence of Start Menu on Windows 8 and Windows Server 2012, you can download a Classic Shell program free from this site.
http://sourceforge.net/projects/classicshell/files/latest/download

Its very easy. Enjoy your cool classic shell start menu. :)



Good Luck.

Upload files using Windows Explorer in SharePoint 2013


If you want to Upload files to a document library using Windows Explorer in SharePoint 2010, you will need to add Desktop Experience feature to your Windows Server. If you want to enable Desktop Experience to Windows Server 2012, follow the steps shown as under:

1. Click Server Manager.
2. Click Add roles and features.

3. You will be prompted with Before You Begin screen. Click Next.
4. Under Insallation Type, select Role based or feature-based installation and click Next.
5. Select the server on which SharePoint is installed from the server pool and click Next.
6. You will see Server Roles. Just click Next.
7. Under Features, scroll down to find User Interfaces and Infrastructure. Expand this node and select    
     Desktop Experience and click Next. This installation also requires installation of Ink and Handwriting
     Services. Finish this wizard and Restart your Server.
8. Now you are ready to use WebDav feature. i.e. You can open a SharePoint library in Windows Explorer.
    You can upload multiple files and folders by Copy and Past or Drag and Drop.

Thanks

Virtual Machines pauses frequently - Hyper V


If you see your Virtual Machines paused frequently, one of the reason could be the host holding the virtual machine ran out of disk. If it is so, free up some space or move your VHD files to another location with ample amount of space.

Good Luck :)

The database prinncipal owns a schema in the database, and cannot be dropped. (Microsoft SQL Server, Error: 15138)

The database prinncipal owns a schema in the database, and cannot be dropped. (Microsoft SQL Server, Error: 15138)

If you created a user for some particular database in SQL Server Management Studio and later tried to delete the user and encountered the problem as shown below, then the solution is simple.




The reason that the user cannot be deleted because this user owns one or some schema in the database. First, you have to change the owner of that schema to some other users. Then you can delete the user.

To change the owner of the schema, expand the Database, expand Security and expand Schemas.


 You will see a list of schema. If you are not sure which schema is owned by that user, right click a schema and see its properties. On the genera page, you can see Schema onwer. Click the search button to find another owner for that schema.


Click Browse

Choose any owner and Click OK.


Now you have changed the owner of the schema previously owned by that user.
Now you can delete the user without any problem.

Change Web URL of a SharePoint List


ChangeWeb URL of a SharePoint List

Sometimes, you may want to change the Web URL of a list or library in SharePoint. Once you create a list or library in SharePoint, it gets its Web URL that you can use the view the list/library. This Web URL depends upon the title that you used for the first time. But changing the title later does not change the Web URL. Here are some simple steps you can use to change the Web URL.

  1. Open the SharePoint site in SharePoint Designer. (You must be site collection administrator).
  2. Click "All Files" tab at the bottom of the left hand navigation pane. This will show all files content on the right pane as shown below.
  3. Click the Lists folder on the right pane. 
  4. Click the list you want to rename. Don't click the List's link, but click in a white space of the List. The list will be highlighted in blue.
  5. Click the Rename button on the top ribbon. 
  6. The Web URL of the list is changed as you desired. But the URL will not be changed in the left navigation in your SharePoint site. Also change it manually.

No Internet Access in Windows XP VM?


No Internet Access in Windows XP VM?

Hi friends,

I created a brand new virtual machine for Windows XP. My host machine is Windows 7 home edition 64 bit. Unfortunately I could not connect to internet. I tried giving my own ip address, still no luck. Diagonizing network connection resulted in following message.


So I opened the port 80, 443 and 21 in Windows Firewall settings, still no luck. Then disabled the windows firewall, restarted the vm, changed the VM settings from Bridged connection to NAT hence and forth still did not helped me. Then I just did the windows update and it was updated successfully. :)

Well guys, don't forget to perform a Windows Update.

How to disable timeout in Outlook Web Access?





Outlook Web Access will time out by default after some period of inactivity. Though this is a secured feature, it seems nuisance when we have to keep logging in frequently while we are occupied with something else. To prevent this, at the logon page you can set the Security option to Private Computer by selecting the Radio Button as shown in image. This will disable the timeout feature. However we are required to Log Off to close the session rather than ju

Outlook Web Access has disabled this link for your security


Outlook Web Access has disabled this link for your security




We must give full URL to the link like http://my-server:portnumber/~/Lists/Issues/EditForm.aspx?ID=10 rather than /Lists/Issues/EditForm.aspx?ID=10

SharePoint Designer 2010 workflow does not start automatically on Item creation.


Workflow cannot be triggered while logged in as System Account. You have to use your own account for this purpose.

Remote Desktop cannot verify the identity of the remote computer because there is a time or date difference between your computer and the remote computer


If you cannot rdp using machine name, you can use ip address to connect it. Once you are able to connect to the remote machine, you can change the time zone or time to match your current time. Then you can connect back using machine name. I had same issue and i solved it this way.

Unable to view list in Data Sheet View in SharePoint 2010


It is imperative that you have Microsoft Office installed in your machine so that you can be able to view a SharePoint list in Datasheet view. You always have 64 bit SharePoint installation. If you have 32 bit Microsoft Office, you don't have any problem. But you won't be able to use datasheet feature if you have 64 bit Office.

No worries. There is solution to every problem. And this one has even easier. Download 2007 Office System Driver Data Connectivity Components.

Caution: This tool must be installed only after you have installed Microsoft Office. If you install this tool first and then setup 64 bit Microsoft Office, it will complain that you have 32 bit Office Component and won't let you install unless you have completely removed the traces of 32 bit Office.

Sharepoint List to PDF report


SharePoint List to PDF report


The easiest way to export SharePoint list to pdf is, first export the list as Excel file. Then save the Excel file as Pdf document.

How do i change font size on the winform datagridview?


How do i change font size on the winform datagridview?



Well, if you want to do it in desing time, right click the datagrid  to view its properties. It has a property called DefaultCellStyle. Click the ellipsis on DefaultCellStyle, then it will present Cell Style Builder window which has the option to change the font size.
Its easy.

All controls freezes after RadGrid Excel Export or Redirecting to another page to a new window in SharePoint 2010


All controls freezes after RadGrid Excel Export or Redirecting to another page to a new window in SharePoint 2010


Add following code to your .aspx or .ascx file


<script type="text/javascript" language="javascript">
    //sharepoint postback to work after clicking on telerik export to pdf
    if (typeof (_spBodyOnLoadFunctionNames) != 'undefined' && _spBodyOnLoadFunctionNames != null) {
        _spBodyOnLoadFunctionNames.push("supressSubmitWraper");
    }

    function supressSubmitWraper() {
        _spSuppressFormOnSubmitWrapper = true;
    }
</script>

Response.Redirect to New Window


Response.Redirect to New Window


If you have multiple buttons and you want one or some buttons to redirect to a page in another window, use following code.

1. Button redirecting to a page in new window

<asp:Button ID="btnNewWindow" runat="Server" Text="New Window"

OnClick="btnNewWindow_Click" OnClientClick="aspnetForm.target ='_blank';"/>

protected void btnNewWindow_Click(
object sender, EventArgs e)
{
Response.Redirect("
NewPage.aspx");
}


2. Button redirecting to a page in same window


<asp:Button ID="btnSameWindow" runat="Server" Text="Same Window"

OnClick="btnSameWindow_Click" OnClientClick="aspnetForm.target ='_self';"/>

protected void btnSameWindow_Click(
object sender, EventArgs e)
{
Response.Redirect("
SomePage.aspx");
}

It is imperative that you add OnClientClick="aspnetForm.target ='_self';" 
on the button in which you want to redirect to a page in Same Window, otherwise
all Response.Redirect in this page will start to open in New Window.

No Java scripts :)