Pages

Monday, December 28, 2015

Check If An Item Exists In SharePoint List

How to check if an item exists in SharePoint list using SPServices?

Pre-requisites:





Solution:


Using below shown SPServices code you can check if an item exists or not in a specific list.

You can use JSOM/REST code as well but that would be an asynchronous call, whereas, SPServices is a synchronous call.

Here, in the CAMLQuery, where I have entered “test”, you can dynamically check for the value coming in from the input box or the textbox of your list "NewForm/EditForm.aspx" page or a control added to your custom page.

This code, you can add to your both list’s “NewForm.aspx” or “EditForm.aspx” and even you can add it to your custom page.

In case, if you are adding it to your “NewForm.aspx” or “EditForm.aspx” then you need to put this inside the “PreSaveAction()” function of SharePoint so that before saving/updating, it can be validated.

To know how to use "PreSaveAction" function, please check it here - https://code.msdn.microsoft.com/office/SharePoint2013-Use-of-a27c804f



Hope this helps!
Read More »

Thursday, August 27, 2015

Cannot connect to the server at this time. Your table cannot be published. - SOLVED

Problem:

While importing data from excel file to SharePoint, user may get below error.


Solution:

This is a issue with permissions a user is having. 

For e.g. if user is having "Contribute" access permission then with “Contribute” access permission level, we don’t have an access to create a list in a site. When we import from excel to SharePoint, SharePoint will create a list and as we do not have a permission to create a list, that’s why user may get this error.

Solution is to elevate your permissions.

Read More »

Wednesday, June 10, 2015

How to display Previous and Next buttons or icons in JQuery Datepicker

Folks,

You must have noticed sometimes while using JQuery datepicker control (which comes from jquery-ui.css file) we get the datepicker control but it doesn't display "Previous" and "Next" buttons or icons as shown below.



The fix is to apply a CSS and display them by using below code.


<style type="text/css">
        .ui-datepicker .ui-datepicker-prev span, .ui-datepicker .ui-datepicker-next span {
            background-image: url("https://your_url_of_the_site/folder_where_images_are_uploaded/ui-icons_ef8c08_256x240.png");
        }
 </style>


Above, you can see I am using a code which apply CSS to your ".aspx" or ".ascx" or ".html" page where you are using this datepicker control.

NoteThe URL I am pointing is to the place where your images are stored. These images are those which comes along with when you download the "jquery-ui" library. In this example, I have stored them in a SharePoint library and I am referencing to them there.

Result comes as shown below after applying the CSS:


Hope this helps!
Read More »

Thursday, May 28, 2015

How to get QueryString from URL using JQuery

QueryString using JQuery

There are lots of ways to get query-string from the web URL by using jQuery but this is the best way I feel to retrieve one or more than one query-strings parameters from the URL.

How to do it?

Let's suppose your URL is http://YourUrl.aspx.

It has 2 query-string parameters i.e. "itemid" and "status".

The parameter "itemid" has value as "1" and parameter "status" has value as "Approve".

So, now your URL will be http://YourUrl.aspx?itemid=1&status=Approve.

In your (document).ready() function, add the code as shown below for the URL which has two query-string parameters (i.e. http://YourUrl.aspx?itemid=1&status=Approve):

  $(document).ready(function () {
            var queryString = new Array();
            if (queryString.length == 0) {
                if (window.location.search.split('?').length > 1) {
                    var params = window.location.search.split('?')[1].split('&');
                    for (var i = 0; i < params.lengthi++) {
                        var key = params[i].split('=')[0];
                        var value = decodeURIComponent(params[i].split('=')[1]);
                        queryString[key] = value;
                    }
                }
            }

            if (queryString["itemid"] != null && queryString["status"] != null) {
                try {
                    alert("Your Item ID is: " + queryString["itemid"] + ", Your Status is:" queryString["status"]);
                }
                catch (e) { }
            }
        });

As you can see that using array variable, we can store more than one query-string parameters and retrieve them by passing their key.

I hope this helps!!

Read More »

Thursday, March 12, 2015

How to order fields in SharePoint custom list's NewForm.aspx page

Ordering fields in SharePoint custom list’s NewForm.aspx page


We have seen that lots of time we need to change the order in which some fields appear on the new list item form (i.e. NewForm.aspx) for any of the SharePoint custom lists. Regardless of the ordering in the view you have selected or created, the fields always seem to appear in the order they were created while creating a custom list on the new item form.

So question comes, how to reorder them?

Well, one way is to create altogether a new form using SharePoint designer and then reorder the column as it will have data view web part.

The other solution which doesn't require SharePoint designer is through content type. To order the columns without using SharePoint designer or creating a new form, follow below steps:

-    Go to the list

-    Go to list settings (from the ribbon in 2013 and 2010, from the drop downs in 2007)

-    Click Advanced settings

-    Ensure ‘allow management of content types’ is checked

-    Go back to the list settings

-    In the list of content types associated with the list, click the one you want to change the order of fields for (in lists that have been created ad hoc this is usually item or document).

-    In the bottom of the screen a link appears called ‘Column order’

-    Click on 'Column order' and then you can order your fields accordingly

-    Once done, click 'OK' button and now create new item and you will see your fields are ordered accordingly
Read More »

Tuesday, January 27, 2015

How to redirect from one page to another in SharePoint Sandbox solutions (especially when they are deployed to SharePoint Online)



How to redirect from one page to another in SharePoint Sandbox solutions (especially when they are deployed to SharePoint Online)?



Answer -


There are lots of ways to achieve this but the following one works almost everywhere for the sandbox solutions.

On a button click event (or accordingly) of your ".cs" file, just add following code:


string pageURL = "www.yourpageurl.com";
var jscript = "<script type='text/javascript'
language='javascript'>window.location='"
+ pageURL + "';</script>";
var literal = new Literal();
literal.Text = jscript;
this.Controls.Add(literal);


The above code will add "Literal" control to page with the specified URL and the page will be redirected to the URL specified.

What is Literal Control?

- The Literal Control is similar to the Label Control as they both are used to display static text on a web page.
- The Literal Control is not inherited from WebControl namespace.
- The Literal Control doesn't provide substantial functionality but Literal text is programmable.
- It doesn't add any HTML elements to the web page. This control makes it possible to add HTML code directly in the code designer window without switching to design view and clicking the HTML button to edit the HTML.
- We cannot apply a style to a literal control.
- Unlike Label control, there is no property like BackColor, ForeColor, BorderColor, BorderStyle, BorderWidth, Height etc. for Literal control.

That makes it more powerful, we can even put a pure HTML contents into it.

When to use Literal Control?
- Literal control is one of the rarely used controls but it is very useful.
Literal control is light weight control.
- The Literal Control is useful when we want to add text to the output of the page dynamically (from the server).
- With that we can even programmatically manipulate the Literal text from the code behind.

In short we can say:

The Literal control is used to display text; that is, it renders static text on a Web page without adding additional HTML tags. It passes content directly to the client browser unless we use the Mode property to encode the content.
 

Read More »

Thursday, January 22, 2015

Change 'Title' Column Display Name Using List Definition In SharePoint

Question: How to change "Title" column display name in default view of a list when creating list by list definition using Visual Studio in SharePoint?

Answer: In Schema.xml file of your list definition project, search for "Fields" tag (i.e. <Fields>) and just before the closing tag of this "Fields" tag (i.e. </Fields> ), put below line of code (also see attached image):

<Field ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Type="Text" Name="LinkTitle" DisplayName="First Name" />

In the above line of code:
ID = ID of your "Title" field
Type = Same as of your "Title" field i.e "Text"
Name = LinkTitle (it will refer to the "Title" text in default view)
DisplayName = The name you want to display in your default view instead of "Title"

Hope this helps!



Read More »

Wednesday, January 7, 2015

Cannot Connect To The SharePoint Site

Cannot Connect To The SharePoint Site

While creating a SharePoint solution in Visual Studio, if you get an error shown in a screenshot below when you validate your SharePoint site URL, just provide user with a "DB_Owner" access to the "WSS_Content", "WSS_Logging" and "SharePoint_Config" database. This will resolve the issue.




Read More »