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()
 

SPgridviewpager Example using c#

Design Code:-

 <SharePoint:SPGridView ID="sgvPagersample" runat="server" AutoGenerateColumns="false" DataSourceID="objSample" AllowPaging="True" PageSize="3">
<Columns>
<asp:BoundField HeaderText="Employee ID" DataField="Title" />
<asp:BoundField HeaderText="Employee Name" DataField="EmpName" />
<asp:BoundField HeaderText="Employee Age" DataField="EmpAge" />
    <asp:BoundField HeaderText="Employee Salary" DataField="EmpSalary" />
</Columns>
</SharePoint:SPGridView>
    <asp:ObjectDataSource ID="objEmp" runat="server" SelectMethod="BindGridView"></asp:ObjectDataSource>
    <center>
    <SharePoint:SPGridViewPager id="sgvPager" runat="Server" GridViewId="sgvPagersample"></SharePoint:SPGridViewPager>
    </center>

Cs Code:-

  protected void Page_Load(object sender, EventArgs e)
        {
            objEmp.TypeName = this.GetType().AssemblyQualifiedName;
        }
        public DataTable BindGridView()
        {
            SPWeb currentWeb = SPContext.Current.Web;
            SPList lstEmployee = currentWeb.Lists["Employee"];
            SPQuery sQuery = new SPQuery();
            sQuery.Query = "<OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy>";
            SPListItemCollection myColl = lstEmployee.GetItems(sQuery);
            return myColl.GetDataTable();
        }

Monday, 7 October 2013

SharePoint People Picker with multi user

Design Code:-
 <table>
    <tr>
        <td>
       <SharePoint:PeopleEditor ID="PplMultiapp" runat="server" Width="250px" Height="25px" MultiSelect="true"/>
        </td>
        <td>
         <asp:Button ID="BtnMutiuser" runat="server" Text="AddMultiuser" OnClick="BtnMutiuser_Click" />
        </td>
    </tr>
</table>

Cs Code:-

 SPFieldUserValueCollection UserCollection = new SPFieldUserValueCollection();
            SPSite oSPsite = new SPSite(SPContext.Current.Site.ID);
            SPWeb oSPWeb = oSPsite.OpenWeb();
            SPList list = oSPWeb.Lists["PeopleList"];
            oSPWeb.AllowUnsafeUpdates = true;
            int iPeople = PplMultiapp.ResolvedEntities.Count;
            SPListItem oSPListItem = list.Items.Add();
            string[] UsersSeperated = PplMultiapp.CommaSeparatedAccounts.Split(',');
            foreach (string UserSeperated in UsersSeperated)
            {
                SPUser User = oSPWeb.SiteUsers[UserSeperated];
                SPFieldUserValue UserName = new SPFieldUserValue(oSPWeb, User.ID, User.LoginName);
                UserCollection.Add(UserName);
            }
            oSPListItem["Title"] = "Test Title";
            oSPListItem["user1"] = UserCollection;
            oSPListItem.Update();

SharePoint People Picker using c#

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

            SPSite oSPsite = new SPSite(SPContext.Current.Site.ID);
            SPWeb oSPWeb = oSPsite.OpenWeb();
            SPList list = oSPWeb.Lists["PeopleList"];
            oSPWeb.AllowUnsafeUpdates = true;
            int iPeople = spPeoplePicker.ResolvedEntities.Count;
             SPListItem itemToAdd = list.Items.Add();
            for (int i = 0; i < iPeople; i++)
            {
                PickerEntity peEntity = spPeoplePicker.ResolvedEntities[i] as PickerEntity;
                SPUser user = SPContext.Current.Web.EnsureUser(peEntity.Key);
                itemToAdd["Title"] = "Test Title";
                itemToAdd["User"] = user;  
                itemToAdd.Update();
            }

To Clear the PeoplePicker

            spPeoplePicker.Accounts.Clear();
            spPeoplePicker.Entities.Clear();

How to change web application port number in sharepoint

1.open "Centeral Administration" ----> "Manage web applications"
2.Select the "Webapplication"
3.Go to the ribbon control click the "Remove Sharepoint from IIS web site"
4.Click "yes"
5.Choose the same "webapplication"
6.Go to the ribbon control click the "Extend" button
7.Enter your Port no.

The password supplied with the username was not correct. Verify that it was entered correctly and try again

Solution:-
Go to command prompt and navigate to bin location of 15 hives
C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\BIN
stsadm -o updatefarmcredentials -userlogin <domainusername> -password <newpassword>
Reset the IIS

How to check the version in IIS

go to control panel
go to Administrative Tools
open IIS(internet Information services)
go to help menu and select About Internet Information Services
and there u can find your IIS version

Sunday, 6 October 2013

Get all library name in sharepoint using powershell


$s = Get-SPSite http://abcd:1111/sites/Demo1/
$wc = $s.AllWebs
foreach($w in $wc)
{
foreach($l in $w.Lists){
if($l.BaseTemplate -eq "DocumentLibrary")
{
Write-Host $l.Title"(Web: "$w.Title")"
}
}
}

Get all TableName and column name with datatypes in sql server

SELECT SysObjects.[Name] as TableName,
SysColumns.[Name] as ColumnName,
CASE SysTypes.[Name]
WHEN
'sysname'THEN
'nvarchar'
ELSE
SysTypes.[Name]
END
AS [Name]
,CASE SysTypes.[Name]
WHEN
'nvarchar'THEN
SysColumns.[Length] / 2
WHEN
'sysname'
THEN
SysColumns.[Length] / 2
ELSE
SysColumns.[Length]
END
AS [Length]
FROM
SysObjects INNER JOIN SysColumns
ON SysObjects.[Id] = SysColumns.[Id]
INNER JOIN SysTypes
ON SysTypes.[xtype] = SysColumns.[xtype]
WHERE SysObjects.[type] = 
'U'ORDER BY SysObjects.[Name

Friday, 4 October 2013

item level permission in SharePoint List

Solution:-

 1. Go to List setting.
 2. Click the Advance setting.
 In advance setting we have "Item-level Permissions" as one of option.
 This option have two sub options. For Read Access
 3. select "Read items that were created by the user"
 For Create and Edit access
 4.select "Create items and edit items that were created by the user"
 5.save the above settings.

SharePoint 2010 manage content and structure missing

Solutions:-

Step:-1

 Site actions
 Site settings
 Site collection administration
 Site collection features
 Activate this feature ‘SharePoint Server Publishing Infrastructure’

Step:-2

Site actions
Site settings-site actions
Manage site features
Activate this feature ‘SharePoint Server Publishing’

watermark example using jquery in asp.net

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript"
        src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js">
    </script>

    <style type="text/css">
        .water {
            font-family: Tahoma, Arial, sans-serif;
            color: gray;
        }
        .txtWidth {
            width: 200px;
        }
    </style>
    <script type="text/javascript">
        $(function () {

            $(".water").each(function () {
                $textbox = $(this);
                if ($textbox.val() != this.title) {
                    $textbox.removeClass("water");
                }
            });

            $(".water").focus(function () {
                $textbox = $(this);
                if ($textbox.val() == this.title) {
                    $textbox.val("");
                    $textbox.removeClass("water");
                }
            });

            $(".water").blur(function () {
                $textbox = $(this);
                if ($.trim($textbox.val()) == "") {
                    $textbox.val(this.title);
                    $textbox.addClass("water");
                }
            });
        });

    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div class="smallDiv">
            <h2>Watermark Example</h2>
            <br />
            <div>
                <asp:TextBox ID="txtUserName" class="water txtWidth" Text="User Name"
                    ToolTip="User Name" runat="server"></asp:TextBox><br />
                <br />
                <asp:TextBox ID="txtPassword" class="water txtWidth" Text="Password"
                    ToolTip="Password" runat="server"></asp:TextBox><br />
                <br />
            </div>
               <br />
            <br />
            <div>
                <asp:Button ID="btnSubmit" runat="server" Text="Login"  />
            </div>
            <br />
            <br />
        </div>
    </form>
</body>
</html>

Wednesday, 2 October 2013

Add Content editor web part in SharePoint 2010

1. Site Action
2. Edit Page
3. Editing Tools ->Insert
4. Web Part
5. Choose Media and Content Categories
6. Content Editor
7. Add


 Rename the Content editor web part in SharePoint 2010
1. Click the Content Editor
2. Edit Web Part
3. under Appearance
 4. Change the Title
5. Ok


Reduce the image size in Content editor

1. Site Action
2. Edit Page
3. Click the Content Editor
4. Edit Web Part
5. Double click the image
6. Picture tools will show in ribbon panel
7. Under Picture tools click Design
8. Then change the Horizontal Size and Vertical Size of the image
9. Save & Close


Add Link icon in Content editor

1. Site Action
2. Edit Page
3. Editing Tools ->Insert
4. Click the image
5. Click the link icon in the ribbon control Enter the Redirect url 

XML Data to CSV file using C#

Xml Code:-

<Employee>
  <Emp>
    <Name>Mohamed</Name>
    <Age>27</Age>
    <Salary>100000</Salary>
  </Emp>
  <Emp>
    <Name>Raja</Name>
    <Age>26</Age>
    <Salary>200000</Salary>
  </Emp>
  <Emp>
    <Name>uthaya</Name>
    <Age>30</Age>
    <Salary>450000</Salary>
  </Emp>
</Employee>

C# Code:-

MemoryStream ms = new MemoryStream();
            DataSet ds = new DataSet();
            ds.ReadXml(@"E:\Student.xml");
            if (ds.Tables[0].Rows.Count > 0)
            {
                StreamWriter writer = new StreamWriter(ms);
                writer.AutoFlush = true;

                foreach (DataColumn column in ds.Tables[0].Columns)
                {
                    writer.Write(column.ColumnName.ToString() + ",");
                }
                writer.WriteLine();

                foreach (DataRow Drow in ds.Tables[0].Rows)
                {
                    writer.Write(Drow["Name"].ToString() + "," + Drow["Age"] + "," + Drow["Salary"].ToString() + ",");
                    writer.WriteLine();
                }
            }
            using (FileStream file = new FileStream("E:\\Output.csv", FileMode.Create, FileAccess.Write))
            {

                ms.WriteTo(file);
            }