Saturday, 19 October 2013

programmatically add edit delete in sharepoint list using c#

Add New Item :-
                   public void AddNewItem()
        {
            SPSecurity.RunWithElevatedPrivileges(delegate
            {
                using (SPSite site = new SPSite(SPContext.Current.Site.ID))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        SPList listEmpInsert = web.Lists["Employee"];
                        web.AllowUnsafeUpdates = true;
                        SPListItem EmpInsert = listEmpInsert.Items.Add();
                        EmpInsert["EmpName"] = "Mohamed";
                        EmpInsert["Age"] = "28";
                        EmpInsert["Address"] = "Chennnai";
                        EmpInsert.Update();
                        web.AllowUnsafeUpdates = false;
                    }
                }
            });
        } 
Update the Item:-
                        public void updateExistingItem()
        {
            SPSecurity.RunWithElevatedPrivileges(delegate
            {
                using (SPSite site = new SPSite(SPContext.Current.Site.ID))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        SPList lstupdate = web.Lists["Employee"];
                        web.AllowUnsafeUpdates = true;
                        int listItemId = 1;
                        SPListItem itemToUpdate = lstupdate.GetItemById(listItemId);
                        itemToUpdate["EmpName"] = "Mohamed sithik";
                        itemToUpdate["Age"] = "30";
                        itemToUpdate["Address"] = "Bangalore";
                        itemToUpdate.Update();
                        web.AllowUnsafeUpdates = false;
                    }
                }
            });
        }
Delete the Item
                           public void DelteItem()
        {
            SPSecurity.RunWithElevatedPrivileges(delegate
            {
                using (SPSite site = new SPSite(SPContext.Current.Site.ID))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        SPList lstdelete = web.Lists["Employee"];
                        web.AllowUnsafeUpdates = true;
                        int listItemId = 1;
                        SPListItem itemToDelete = lstdelete.GetItemById(listItemId);
                        itemToDelete.Delete();
                        web.AllowUnsafeUpdates = false;
                    }
                }
            });
        }
Get all the Item:-
              public void ReteriveallItem() 
        {
            SPSite mySite = new SPSite(SPContext.Current.Site.ID);
            SPWeb myWeb = mySite.OpenWeb();
            SPList myList = myWeb.Lists["Employee"];
            DataTable dt = ConvertSPListToDataTable(myList);
          
        }
        private static DataTable ConvertSPListToDataTable(SPList oList)
        {
            DataTable dt = new DataTable();
            try
            {
                dt = oList.Items.GetDataTable();
                foreach (DataColumn c in dt.Columns)
                    c.ColumnName = System.Xml.XmlConvert.DecodeName(c.ColumnName);
                return (dt);
            }
            catch
            {
                return (dt);
            }
        }



Thursday, 17 October 2013

we are having a problem opening this location in file explorer sharepoint 2013

Solution:-
            Just add the Desktop Experience

Refer the below link

http://www.win2012workstation.com/desktop-experience/

open with explorer sharepoint disabled

Solution:-

Just open the same Document in Internet Explorer(IE)

Friday, 11 October 2013

sign in different user missing in sharepoint 2013

1.Just open the following file

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\CONTROLTEMPLATES\Welcome.ascx

2.Add the below line inside the file

<SharePoint:MenuItemTemplate runat="server" ID="ID_LoginAsDifferentUser" 
Text="<%$Resources:wss,personalactions_loginasdifferentuser%>"  
Description="<%$Resources:wss,personalactions_loginasdifferentuserdescription%>"  
MenuGroupId="100"   Sequence="100"   UseShortId="true"   />





3. save it

Thursday, 10 October 2013

Rename ContentDataBaseName in SharePoint Using SQLQuery

Alter ContentDb Name
USE MASTER;
GO
ALTER DATABASE [WSS_Content_fdc3317e5897456ab294ef998ec46420]
SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
ALTER DATABASE [WSS_Content_fdc3317e5897456ab294ef998ec46420]
MODIFY NAME= WSS_Content4;
GO
ALTER DATABASE WSS_Content4
SET MULTI_USER
GO

Delete SharePoint Content DataBase using PowerShell

Syntax:-

Remove-SPWebApplication http://sitename -Confirm -DeleteIISSite -RemoveContentDatabases

Example:-

Remove-SPWebApplication http://abcd01:1111/ -Confirm -DeleteIISSite -RemoveContentDatabases

Wednesday, 9 October 2013

move site collection from one web application to another web application using powershell

Example Script:-


#Get the from Site Collection URL
$fromURL = "http://Abcd:5000/sites/Fromsite"
#Get the to Site Collection URL
$toURL = "http://sfs01:4000/sites/Rsite3/"

#Location to the backup file directory to store Site Collection backup files
$backupPath = "C:\\SiteBK.bak"

#Backing up Site Collection prior to moving
Write-Host "Backing Up Site Collection…."
Backup-SPSite $fromURL -Path C:\SiteBK.bak -force

#Removing Site Collection from old web application path
Write-Host "Removing Site Collection from old managed path location…"
Remove-SPSite -Identity $fromURL -Confirm:$false

#Restoring Site Collection to new Managed Path
Write-Host "Restoring Site Collection to new managed path location…"
Restore-SPSite -Identity $toURL -Path c:\SiteBK.bak -Confirm:$false

#Remove backup files from the backup dirctory
Remove-Item c:\SiteBK.bak

delete sharepoint web application using powershell

Syntax:-
Remove-SPWebApplication "http://sitename" -Confirm -DeleteIISSite -RemoveContentDatabases

Example:-
Remove-SPWebApplication "http://Abcd:1111/" -Confirm -DeleteIISSite -RemoveContentDatabases

The Root Certificate that was just selected is invalid. This may be because the selected certificate requires a password

Solution:-
                  am using IE Browser its works for me...

Tuesday, 8 October 2013

Enable and Disable SharePoint Developer Dashboard with PowerShell

Enable:-

$devdash = [Microsoft.SharePoint.Administration.SPWebService]::ContentService.DeveloperDashboardSettings;
$devdash.DisplayLevel = “OnDemand”;
$devdash.TraceEnabled = $false;
$devdash.Update()
Disable :-
 
$devdash = [Microsoft.SharePoint.Administration.SPWebService]::ContentService.DeveloperDashboardSettings;
$devdash.DisplayLevel = “Off”;
$devdash.TraceEnabled = $true;
$devdash.Update()