Thursday, 27 October 2016

SPQuery: Cannot complete this action. Please try again?


"Cannot complete this action" = "Error in the CAML syntax".

Zoom in and look for the error!

Wednesday, 26 October 2016

How to deploy a custom master page from SharePoint farm solution.



Right click on your project > Add New Item > Module

Rename Sample.txt to MyCustomMaster.master

Replace the content of Element.xml with following:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

  <Module Name="CustomMasterPages" Url="_catalogs/masterpage" List="116">

    <File  Url="MyCustomMaster.master" Path="CustomMasterPages\MyCustomMaster.master" Type="GhostableInLibrary" IgnoreIfAlreadyExists="FALSE" >

      <Property Name="UIVersion" Value="15"></Property>
      <Property Name="MasterPageDescription" Value="This is the master page for custom pages." />
      <Property Name="ContentType" Value="$Resources:cmscore,contenttype_masterpage_name;" />
    </File>
  </Module>
</Elements>


Refer it like this from your pages:

MasterPageFile="/_catalogs/masterpage/MyCustomMaster.master"


How to refer a custom master page from a SharePoint Application page?


To refer a custom master page from an application page you should put both the files under the same layout folder in your SharePoint farm solution.

Then you can refer to the master page using the following tag from the application page:

MasterPageFile="MasterPages/MyCustomMaster.master"


Workaround to refer master page gallery from an application page:

protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
SPWeb web= SPControl.GetContextSite(Context).OpenWeb();
string strUrl = web.ServerRelativeUrl + “/_catalogs/masterpage/MyCustomMaster.master”;
this.MasterPageFile = strUrl;
}

SharePoint: Site pages vs Application pages.


Site Pages
These Pages are stored in the Content Database and they are parsed when requested by user. A typical web part page is an example of Site Pages. They can be edited, modified by the Power Users and customized according to their needs.
Application Pages
They are same as ASP.net Pages and stored on the layouts folder of SharePoint front end web server. When user requests , application pages are compiled and they are much faster than Site Pages. Admin Pages like settings.aspx, accessdenied.aspx are an example of Application Pages.

Friday, 21 October 2016

SharePoint Designer: How to add an if condition around an existing workflow statement?


Add the if condition, which you missed earlier, right above the statement you need inside the if block.

Then go to the properties of the statement and select 'move action up'.



SharePoint Designer: How to add an if condition around an existing workflow statement?

Wednesday, 12 October 2016

How to hide password while entering it on C# console application?


static void Main(string[] args)
        {
            string user;
            Console.Write("Enter your user name: ");
            user = Console.ReadLine();

            string pwd = "";
            Console.Write("Enter your password: ");
            ConsoleKeyInfo key;
            do
            {
                input = Console.ReadKey(true);

                if (input.Key != ConsoleKey.Backspace && input.Key != ConsoleKey.Enter)
                {
                    pwd += input.KeyChar;
                    Console.Write("*");
                }
                else
                {
                    if (input.Key == ConsoleKey.Backspace && pass.Length > 0)
                    {
                        pwd = pwd.Substring(0, (pwd.Length - 1));
                        Console.Write("\b \b");
                    }
                }
            }
            while (input.Key != ConsoleKey.Enter);
            CallYourMethod(user, pwd);
        }