Showing posts with label sharepoint. Show all posts
Showing posts with label sharepoint. Show all posts

November 09, 2014

SharePoint Uninstall, Remove, Add, Install SPSolution .wsp using PowerShell or STSADM

This is gonna very often command that you will keep using to Add and Activate solution in SharePoint Environment so you can bookmark it or follow the blog.

Well the deployment process includes below set of steps to Remove and Add Solutions in SharePoint.
1.      Retract
2.      Remove
3.      Add
4.      Deploy

First Deactivate Solution then Remove Solution, then Add Solution from local drive and Activate to desired scope.

There are 3 simple ways to do so.
·        From SharePoint site, go deactivate then from CA retract and remove solution.
·        Second way is STSADM.exe
·        Third and most preferred way is PowerShell.

Uninstalling SharePoint wsp package using PowerShell command

Uninstall-SPSolution –Identity “MySolution.wsp” –WebApplication “WebApp Url”

Remove SharePoint wsp package using PowerShell command

Remove-SPSolution–Identity "MySolution.wsp"

Add SharePoint wsp package using PowerShell command

Add -SPSolution "C:\Praveen\MySolution.wsp"

Installing SharePoint wsp package using PowerShell command

Install-SPSolution –Identity "MySolution.wsp" –WebApplication "url" –GACDeployment

Using STSADM command

open command prompt and Go to path,
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\BIN
 
Add Solution
stsadm.exe -o addsolution -filename "c:\Praveen\MySolution.wsp"
 
Deploy Solution
stsadm.exe -o deploysolution -name "MySolution.wsp" -url "http://server/" -allowgacdeployment -immediate

Activate feature
stsadm.exe -o activatefeature -name "MySolution.wsp" -url "http://server/"




--
Regards,
Praveen Pandit



September 07, 2014

Production Server maintance daily alert email using powershell, check free space

Well we have number of servers for productions so going to each server (WFE, DB, Application and DMZ servers) etc and checking for frees pace and running services etc that's really hectic and that it time consuming environment that may have 4WFE 2DB 1Application and 1DMZ server.

In short we should create task scheduler and run PowerShell script that can check for free space, running services and process etc... and send 1 email for all these details.

Here I am sharing sample script :
1) Production Server maintenance daily alert email using powershell:checking free space of C drive.



You can download above code to check free space, from here.



--
Thanks,
Praveen Pandit

May 04, 2014

SharePoint 2013 auto fill people picker, auto fill people editor in application page (aspx) C#

Microsoft always comes with some new and more user friendly features in every new version. Well this client people picker (which is auto fill by user name, email or login id) new and simple control introduced in SharePoint 2013, that will save lot of time of ours.

instead of using below people picker of sharepoint 2010

<SharePoint:PeopleEditor ID="spPeoplePicker" runat="server" Width="350" SelectionSet="User" />

and setting javascript we can use  PeopleEditor to make it easy and faster for end user we can use below control in SP2013

aspx syntax :
<SharePoint:ClientPeoplePicker ValidationEnabled="true" ID="pplDemo" runat="server" VisibleSuggestions="5" AutoFillEnabled="True" AllowEmailAddresses="true" Rows="1" AllowMultipleEntities="false" CssClass="ms-long ms-spellcheck-true" Height="85px"  />



C# Code to get SPUser:
if( pplDemo.ResolvedEntities.Count > 0)
{
SPUser oUser = oWeb.SiteUsers[((PickerEntity)pplDemo.ResolvedEntities[0]).Key];

                         if (oUser != null)
                         {
                              // do your stuff.
                         }
}

C# Code to Set User to Client People Picker control:
 
 pplDemo.InitialUserAccounts = "UserEmail1";
 



Thanks,
remaining getting and saving values in SharePoint is same as earlier.

You can Share your findings or issue here.


--
Thanks,
Praveen Pandit

March 16, 2014

SharePoint read csv or xml file from wsp / solution of _layouts file.





SharePoint how to read any csv or xml file in webpart using C# code.

Usually we doesn’t required this scenario, but in some cases you want to keep any config data or aby xml data apart from typical SPList you have to create a Config or default setting file that cabn be access by your C# code,



Finally you want to get file that you have mapped in _layouts so using StreamReader / Stream or File.Open(); it needs file’s absolute path and if you are in SharePoint wsp so that makes you to follow approach like below,

In file path string pass below way


SharePoint – C# get xml file from _layouts
Server.MapPath(“/_layouts/mySolutionFolder/myXml.xml”);
Read external file in SharePoint C#







Thanks,

Praveen Pandit




December 29, 2013

SHarePoint get List of Specific (Task, GenericList, DocumentLibrary, Announcements) Object Model C#



 SharePoint saves everything in format of list below are few type of Lists those we use frequently.
  • GenericList
  • DocumentLibrary
  • Survey
  • Announcements
  • Contacts
  • Tasks
Complete List Type template can be found here

Now some time it happens your clients come up with some requirement and you have to get all list of specific Type of SPList. its not big deal ;)

Suppose I have 20 list few are Task type few Announcement Type and few are generic list, Now I wants only those list whose Template Type is Announcement.


C# Code:
using (SPWeb oWeb = SPContext.Current.Site.OpenWeb("\RelaviteUrl",false))
            {
                foreach(SPList oList in oWeb.Lists)
                {
                    if (SPListTemplateType.Announcements == oList.BaseTemplate)
                    {
                        //(oList.Title);
                    }                
                }                
            }



Please share any issue or findings on this. 


--
Regards,
Praveen Pandit