Friday, July 14, 2017

Change Calendar Days Name to short 3 characters

Hello,

This was a simple requirement where the ask was to change the Days' name from Full (Sunday, Monday,...) to Sun, Mon Etc. OOTB- there is no option to achieve this.

And here comes the power of jquery where we can target specific Table heading (Calendar is made as HTML Table). Look at the following HTML:

So we will be using Jquery to target all the highlighted section as follows and Get First 3 Characters and replace the text of the target cell.

 $("table.ms-acal-month > tbody > tr > th.ms-acal-month-top").each(function(){
            // get the first 3 chars from day name
        $cell = $(this).text().substring(0,3);
        $(this).text($cell);
   }); 


The above code can be used anywhere such as document.ready etc.

I added Content Editor Webpart and added following and Job was done:

<script  type="text/javascript"  src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js"></script>
<script language="javascript">
$(document).ready(function() {
     $("table.ms-acal-month > tbody > tr > th.ms-acal-month-top").each(function(){
            // get the first 3 chars from day name
        $cell = $(this).text().substring(0,3);
        $(this).text($cell);

   });
});
</script>

Tuesday, April 2, 2013

Easy but worth publishing.. Uploading document to Doc Library via Code..


 public static void PushFileToDocLib()
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite site = new SPSite("site url"))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                       
                        string fileToUpload = "c:\\ExcelWorkBookName.xlsx";
                        if (!System.IO.File.Exists(fileToUpload))
                            throw new FileNotFoundException("File Not Found", fileToUpload);
                        SPFolder docLibrary = web.Folders["Document Lib Name"];
                        Boolean ExistingFiles = true;
                        string fileName = System.IO.Path.GetFileName(fileToUpload);
                        FileStream fileStream = File.OpenRead(fileToUpload);
                        SPFile spFile = docLibrary.Files.Add(fileName, fileStream, ExistingFiles);
                        docLibrary.Update();



                    }
                }
            });
        }

Tuesday, January 15, 2013

Enable/Disable Asp validators via Javascript..

Yes.. it is among the most fundamental functions of javascript but I admit that i didnt know about it. So i tend to share to those who sometime somewhere stands on my feet.

Ok, there is a function call ValidatorEnable(control, bool status).

This function enables/disables the validator control specified as parameter in the fucntion.

For Eg:
function ActivateValidator(Ctrl) {

      alert(Ctrl.value.length);
      if (Ctrl.value.length > 0) {
            var myValidator = document.getElementById('<%=rfvLowTier.ClientID %>');
            ValidatorEnable(myValidator, true);
}     Hope this helps!

Wednesday, September 12, 2012

Kerberos--

Guys.. I m preparing small documetation regarding the Kerberos in Sharepoint and the double hop issues.
Meantime, if you guys have any related issues with Sharepoint Kervberos, feel free to post questions.

We got one while trying to connect to OLAP via custom webpart where we were not able to connect to OLAP cube. Finally we nailed it down and saw another beauty of Kerberos.

Roshan

Tuesday, March 6, 2012

LINQ to SQL not updating the record in the table

Hi,

I was using LINQ to SQL (first time to be honest) and i was excited. So one of my task was to update db table for which i used the following code.

MPSCGetDataFromDBDataContext dc = new MPSCGetDataFromDBDataContext();
MPSC_WFStatus wfStatus = dc.MPSC_WFStatus.Single(p => p.WFID == item.WFID);
wfStatus.IsNew = 1;
dc.SubmitChanges();

But it was not updating the data table. So after hitting my head on wall for a while, finally i broke it and found the silly mistake that i made:
---- Define Primary key on dbml.

aha... what a relief.. its updating the tables. Just posting incase any of you are in the same situation.

-Cheers!

Thursday, October 27, 2011

Accessing Sharepoint DateTimeControl in Javascript

Hi Guys,

I thought it worth posting this on how to access the sharepoint DatetimeControl in case if you are creating custom webparts with this controls or writing some custom javascripts.

in javascript:


function GetDate()
{
var sdate=document.getElementbyId('<%=dateControlName.Controls[0].ClientID %>');
alert (sdate.value);
}

Cheers!

Thursday, September 23, 2010

Getting List Internal Name

Hi Guys,
I ran into a very wierd but intresting issue today. The client changed the document library name and suddenly even handler started throwing error saying the file path does not matched. Whenever the list name changes, the internal name remains same and the path of the file remains with the internal name. So my properties.ListTitle was picking the display name and could not find the file.

So always better approach is to use list internal name.
Not simple but not even complex:
I used

properties.ListItem.ListItems.List.RootFolder.Name

and it gave me the list internal name and the issue was fixed. Cheers!

So, the basic logic is that, if you want to use list internal name, then you have to follow

objList.RootFolder.Name