About Me

My photo
a Dynamic and Energetic guy.....

Monday, December 8, 2014

How to Upgrade A SharePoint App


When we develop SharePoint App we can’t do fresh deployment every time. We have to upgrade our solution when changes append to the system. There are few thing that we have to do in the code for upgrades. But here we are doing the deployment steps.
First we have to go to the APP and get the version.

Our next deployment should be grater than the current version of the APP. We can get the version using APPMANIFEST.xml


Now we have to use PowerShell commands to upgrade the solution. First we have to IMPORT the package to server.

It will pop up to packages from the TRUSTED SOURCES.
 Once we PRESS Y, it will import to the site collection.

When we get the instance of the APP, we can execute Upgrade function.

When executing it, we can see Site collection also updating the APP.


So we will only update the APP, not a full deployment.


$spapp = Import-SPAppPackage -Path E:\Deployment\TRCA.app -Site http://spsvr:1111 -Source ([microsoft.sharepoint.administration.spappsource]::ObjectModel)

$instances = Get-SPAppInstance -Web http://spsvr:1111

Update-SPAppInstance -Identity $instances[2] -App $spapp

Monday, October 20, 2014

Change SharePoint Title

When we need to change the SharePoint Title from the Site collection,
We can use PowerShell Command.

PS C:\Users\Administrator> $app = Get-SPWebApplication -Identity http://spsvr:1111

PS C:\Users\Administrator> $app.SuiteBarBrandingElementHtml = "<div class='ms-core-brandingText'></div>"
PS C:\Users\Administrator> $app.Update()
PS C:\Users\Administrator>


Now can see the Chaned TEXT. If we don't want anything we can set "EMPTY".

Sunday, October 19, 2014

SharePoint Calendar Using HTML




When we need a CALEDAR runs on SharePoint. We can simply use a HTML calendar.
It will display whole month, highlight the CUREENT date.
Whet we have to do is,
1)      Add a SCRIPT EDITOR to SharePoint page
2)      Add following code snippet and save it.

<html>
<title>www.scriptSplash.com => javaScript - Basic Calendar</title>
<head>
<style type="text/css">
.calendarTable {
    background-color:#eee;
    color:#333;
    border: 1px solid #bbb;
}
.calendarTable td {
    text-align: center;
    padding: 2px 4px 2px 4px;
}
.calendarTable td.monthHead {
    font-weight: bold;
    border: 1px solid #bbb;
    background-color:#ddd;
}
.calendarTable td.weekDay {
    font-weight: bold;
}
.calendarTable td.monthDay {
    border: 1px solid #ddd;
}
.calendarTable td.currentDay {
    font-weight: bold;
    color:#ad5;
    border: 1px solid #aaa;
}
</style>
<script type="text/javascript" language="javascript">
/** Function to display a Calendar based on javascript. **/
function calendar() {
  // Get the current date parameters.
  var date = new Date();
  var day = date.getDate();
  var month = date.getMonth();
  var year = date.getFullYear();
 
  var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
  var monthDays = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
  var weekDay = new Array('Mo','Tu','We','Th','Fr','Sa','Su');
  var days_in_this_month = monthDays[month];

  // Create the basic Calendar structure.
  var calendar_html = '<table class="calendarTable">';
  calendar_html += '<tr><td class="monthHead" colspan="7">' + months[month] + ' ' + year + '</td></tr>';
  calendar_html += '<tr>';
  var first_week_day = new Date(year, month, 1).getDay();
  for(week_day= 0; week_day < 7; week_day++) {
    calendar_html += '<td class="weekDay">' + weekDay[week_day] + '</td>';
  }
  calendar_html += '</tr><tr>';

  // Fill the first week of the month with the appropriate number of blanks.
  for(week_day = 0; week_day < first_week_day; week_day++) {
    calendar_html += '<td> </td>';
  }
  week_day = first_week_day;
  for(day_counter = 1; day_counter <= days_in_this_month; day_counter++) {
    week_day %= 7;
    if(week_day == 0)
      calendar_html += '</tr><tr>';
    // Do something different for the current day.
    if(day == day_counter) {
      calendar_html += '<td class="currentDay">' + day_counter + '</td>';
    } else {
      calendar_html += '<td class="monthDay"> ' + day_counter + ' </td>';
 }
    week_day++;
  }
  calendar_html += '</tr>';
  calendar_html += '</table>';
  // Display the calendar.
  document.write(calendar_html);
}
</script>
</head>
<body>
  <h2> Basic Calendar </h2>
  <br/>
  <script type="text/javascript">calendar();</script>
</body>

</html>

Wednesday, June 18, 2014

View Health / Usage Reports in SharePoint 2013

We can get full detail of Usage within SharePoint Farm.
First we have to enable Logging in Central Administration


Set "Least critical event to report to the event log" as VERBOSE
Set "Least critical event to report to the trace log " as VERBOSE.
All the usage data will be tracked in the farm.

Then go to CA --> Monitoring --> View Health Reports

There we can see "SLOWEST PAGES" section. We can set the FARM and Web Application. When we click GO, it displays an error.



 The error explains the error regarding Database status.

We have to open Database "WSS_Logging". The we have to find the Stored Procedure mapped with the error.


We have to Modify the Stored Procedure. There we have to comment the "WITH (READPAST)" text. 


The Execute it.


Now we can run the report. We can see the full data with Slowest Page URLs and number of requests.



We have to wait some time to get real time data, mainly till the SharePoint timer job runs and collect the data.

Add A WebPart to SharePoint Page Programatically Throws File CheckOut exception

When we add a WebPart to a page, programatically we have to checkout the page.

Even we try to Checkout the file using C# code, it throws the exception.
We have to go to the Document library that resides the required page.
Then go to the Library settings section.


Then go to the Versioning settings Section.
We have to set NO to "Require Checkout" option.

Then Our Webpart will be deployed to the page successfully.





Friday, May 9, 2014

Execution of PowerShell Script is disabled on the system

When we RUN PowerShell Scripts, we are getting "PowerShell Script is disabled on the system"

This is mainly because of EXECUTION POLICY.


We can run the command and get the CURRENT security status. It is "Restricted"

So we have to increase security for Scripts.

No, we can't increase Security if we are not running the Command Prompt with elevated privileges.
Yes, Now the Security level is upgraded.

Now we can run POWERSHELL Scripts.





Thursday, May 8, 2014

Delete files using PowerShell based on Created Time

We have to clean our SharePoint backup location after 7 days.
We have decided to create a POWERSHELL script and run it as a WINDOWS TIMER.
It is simple.

The PowerShell Script,

# Change the value $oldTime in order to set a limit for files to be deleted.
$oldTime = [int]1 # 30 days
foreach ($path in Get-Content "pathList.txt") {
# Write information of what it is about to do
Write-Host "Trying to delete files older than $oldTime days, in the folder $path" -ForegroundColor Green
# deleting the old files
Get-ChildItem $path -Recurse -Include "*.PNG", "*.bak" | WHERE {($_.LastWriteTime  -le $(Get-Date).AddDays(-$oldTime))} | Remove-Item -Force
}



there we have set 3 parameters.
Filepath   = the folder that we needs to clean
DAYS    = deleting files older than this DAYS
Types     = the file types that we need to delete

the "pathList.txt" has all the File paths that we have to delete.

 


We can delete SELECTED file types.


After we run the script, we can see all the FILES TYPES (.png) been deleted if OLDER than specify DAYS.

We can set a windows timer service and execute the .ps1 file



Tuesday, May 6, 2014

Get Data from a Forum / Discussion Board in SharePoint

======================FORUM, TITLE column==============

SPQuery query = new SPQuery();
query.Query = string.Concat(
    "<Where>",
        "<Eq>",
            "<FieldRef Name='IsRootPost'/>",
            "<Value Type='Number'>1</Value>",
        "</Eq>",
    "</Where>",
    "<OrderBy>",
        "<FieldRef Name='DiscussionTitle' Ascending='TRUE' />",
    "</OrderBy>");
query.ViewFields = "<FieldRef Name='DiscussionTitle' />";
query.ViewFieldsOnly = true;

SPListItemCollection _items = [MyList].GetItems(query);'

Sunday, April 27, 2014

Add a FBA User to a SharePoint Group Programatically

SPSecurity.RunWithElevatedPrivileges(delegate
                               {
                                   using (SPSite site = new SPSite(SPContext.Current.Web.Url))
                                   {
                                       using (SPWeb web = site.OpenWeb())
                                       {
                                           //adding user to the contributor group
                                           web.AllowUnsafeUpdates = true;
                                           //i:0#.f|sql-membershipprovider|chana

                                           string usernameWithProvider = "i:0#.f|sql-membershipprovider|" + usr.UserName;
                                          
                                           web.AllUsers.Add(usernameWithProvider, txtUserName.Text, txtUserName.Text, "");
                                           try
                                           {
                                               SPUser spuser = web.AllUsers[usernameWithProvider];
                                               if (spuser != null)
                                               {
                                                   SPGroup spGroup = web.Groups["Dev Members"];

                                                   if (spGroup != null)
                                                       spGroup.AddUser(spuser);
                                                   web.Update();
                                                   web.AllowUnsafeUpdates = false;
                                               }
                                           }
                                           catch { }
                                           web.Update();
                                           web.AllowUnsafeUpdates = false;
                                       }
                                   }

                               });

Monday, March 17, 2014

SharePoint User Token Code

try
            {
                SPSite tempSite = new SPSite(siteURL);
                string loginNameInFull = @"i:0#.w|" + username;
                SPUserToken userToken = tempSite.OpenWeb().AllUsers[loginNameInFull].UserToken;
                using (SPSite site = new SPSite(siteURL, userToken))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        SPList olist = web.Lists[listName];
                        SPListItemCollection ocol = olist.Items;
                        return ocol;
                    }
                }
            }

This is passing credentials to Windows Authentication
UserName append with "i:0#w|" 


Sunday, February 16, 2014

Convert EXCEL file to Project Plan

When we have data in an EXCEL with number of dates, we can convert that data to Project Plan without any other software.




Got the excel magic from


My Masters