Friday, 23 August 2013

bind SharePoint discussion board reply in repeater using c#

Design code :-

<asp:Repeater ID="rptMain" OnItemDataBound="Repeater1_ItemDataBound" runat="server">
    <ItemTemplate>
        <h1><%#Eval("Title") %></h1>
        <asp:HiddenField  ID="hdnparentid" Value='<%#Eval("ID") %>' runat="server" />
        <asp:Repeater ID="rptChild" runat="server">
            <ItemTemplate>
                <asp:Literal ID="ltrchildbody" Text='<%#Eval("Body") %>' runat="server"></asp:Literal>
            </ItemTemplate>
        </asp:Repeater>
    </ItemTemplate>
</asp:Repeater>

Cs code:-

  protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType==ListItemType.AlternatingItem)
            {

                HiddenField hdnid = (HiddenField)e.Item.FindControl("hdnparentid");
                Repeater rptchild = (Repeater)e.Item.FindControl("rptChild");
                if (rptchild != null)
                {
                    using (SPSite site = new SPSite(SPContext.Current.Site.ID))
                    {
                        using (SPWeb web = site.OpenWeb())
                        {
                            SPList list = web.Lists.TryGetList("DiscussionList");
                            if (list != null)
                            {

                                SPFolder t = list.GetItemById(Convert.ToInt32(hdnid.Value)).Folder;
                                SPQuery q = new SPQuery();
                                q.Folder = t;
                                SPListItemCollection res = list.GetItems(q);
                                DataTable dt = new DataTable();
                                dt = res.GetDataTable();

                                rptchild.DataSource = dt;
                                rptchild.DataBind();
                            }
                        }
                    }

                   
                }

               
            }
        }
       public  void GetDisscussionTitles()
        {
            using (SPSite site = new SPSite(SPContext.Current.Site.ID))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPList list = web.Lists.TryGetList("DiscussionList");
                    if (list != null)
                    {
                        // Empty Query is passed to get only the discussion topics
                        SPListItemCollection itemColl = list.GetItems(new SPQuery());
                        DataTable dtmain = itemColl.GetDataTable();
                        rptMain.DataSource = dtmain;
                        rptMain.DataBind();

                    }
               }
            }
        }

Upload STP File to the List Template Gallery in SharePoint using PowerShell

    1.Click "Start" button
    2.Choose the "Microsoft SharePoint 2010 Products"
    3.Click the "SharePoint 2010 Management Shell" [ run as Administrator ]

Syntax:-

   $web = Get-SPWeb "SiteCollectionURL"
   $spFolder = $web.GetFolder("List Template Gallery")
   $spFileCollection = $spFolder.Files
   $file = Get-ChildItem "StpfilePath"
   $spFileCollection.Add("_catalogs/lt/StpFileName", $file.OpenRead(), $true)

Example:-
   
  $web = Get-SPWeb "http://Abcd/sites/SamSite"
  $spFolder = $web.GetFolder("List Template Gallery")
  $spFileCollection = $spFolder.Files
  $file = Get-ChildItem "C:\Users\Administrator\Desktop\Mohamed sithik\Employee.stp"
  $spFileCollection.Add("_catalogs/lt/Employee.stp", $file.OpenRead(), $true)

Thursday, 22 August 2013

how to get w3wp process id for a application pool in sharepoint

1. Open command prompt
2. Type the below commands and run it..


Syntax:-
             tasklist /M SolutionName.dll
Example:-
             tasklist /M SPF.Online.Exam.dll

error occured in deployment step add solution


Solution:-
              1.Reset the IIS

Monday, 19 August 2013

import Multiple files to SharePoint document library using powershell

Script:-

   if((Get-PSSnapin "Microsoft.SharePoint.PowerShell") -eq $null)
{
    Add-PSSnapin Microsoft.SharePoint.PowerShell
}

#Script settings

$webUrl = "Site Collection URL"

$docLibraryName = "Documents"
$docLibraryUrlName = "Shared%20Documents"

$localFolderPath = "C:\temp\Docs4SharePoint"

#Open web and library

$web = Get-SPWeb $webUrl

$docLibrary = $web.Lists[$docLibraryName]

$files = ([System.IO.DirectoryInfo] (Get-Item $localFolderPath)).GetFiles()

ForEach($file in $files)
{

    #Open file
    $fileStream = ([System.IO.FileInfo] (Get-Item $file.FullName)).OpenRead()

    #Add file
    $folder =  $web.getfolder($docLibraryUrlName)

    write-host "Copying file " $file.Name " to " $folder.ServerRelativeUrl "..."
    $spFile = $folder.Files.Add($folder.Url + "/" + $file.Name, [System.IO.Stream]$fileStream, $true)
    write-host "Success"

    #Close file stream
    $fileStream.Close();
}

#Dispose web

$web.Dispose()

import excel data to sharepoint 2010 list using powershell

    1.Click "Start" button
    2.Choose the "Microsoft SharePoint 2010 Products"
    3.Click the "SharePoint 2010 Management Shell" [ run as Administrator ]

Script

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Read the CSV file - Map the Columns to Named Header (CSV File doesn't has Column Header)
$CSVData = Import-CSV -path "C:\Data.csv" -Header("Title", "Description")

#Get the Web
$web = Get-SPWeb -identity "Site Collection URL"

#Get the Target List
$list = $web.Lists["List Name"]

#Iterate through each Row in the CSV
foreach ($row in $CSVData)
{
$item = $list.Items.Add();
$item["Title"] = $row.Title
$item["Description"] = $row.Description
$item.Update()

Tuesday, 13 August 2013

save list as custom template using PowerShell

Powershell Script:-

              $site = get-spsite("http://abcd:12312/sites/Sample/")
              $web = $site.RootWeb
              $list = $web.Lists["MyCustomListName"]
              $list.SaveAsTemplate("MyCustomListTemplate.stp",                                                                                   "MyCustomListTemplate","MyCustomList Template", $false)
              $listTemplates = $site.GetCustomListTemplates($web)
              $web.Lists.Add("MyCustomNewList", "My CustomNew List",                                                                               $listTemplates["MyCustomListTemplate"])

Note:-
             http://abcd:12312/sites/Sample/=site collection url
             MyCustomListName =CustomList Name
             MyCustomListTemplate.stp =stp file Name




How to count the the total number of item in Sharepoint list using Powershell

powershell script :-

      $spWeb = Get-SPWeb "http://abcd:12312/sites/Sample/"
      $spList = $spWeb.Lists["MysampleCustomList"]
      $spListItems = $spList.Items
      Write-Host $spListItems.Count

Note:-

    http://abcd:12312/sites/Sample/ =Site collection url
    MysampleCustomList = ListName
     

How to Check if your SharePoint 2010 Web Application Uses Claims Authentication



$web = Get-SPWebApplication "http://abcd:12312/sites/Sample"
$web.UseClaimsAuthentication

Note:-
   http://abcd:12312/sites/Sample =site collection url

How to Import the Multiple file to SharePoint Document Library using PowerShell

if((Get-PSSnapin "Microsoft.SharePoint.PowerShell") -eq $null)
{
    Add-PSSnapin Microsoft.SharePoint.PowerShell
}

#Script settings

$webUrl = "http://abcd:12312/sites/Sample"

$docLibraryName = "Documents"
$docLibraryUrlName = "Shared%20Documents"

$localFolderPath = "C:\temp\Docs4SharePoint"

#Open web and library

$web = Get-SPWeb $webUrl

$docLibrary = $web.Lists[$docLibraryName]

$files = ([System.IO.DirectoryInfo] (Get-Item $localFolderPath)).GetFiles()

ForEach($file in $files)
{

    #Open file
    $fileStream = ([System.IO.FileInfo] (Get-Item $file.FullName)).OpenRead()

    #Add file
    $folder =  $web.getfolder($docLibraryUrlName)

    write-host "Copying file " $file.Name " to " $folder.ServerRelativeUrl "..."
    $spFile = $folder.Files.Add($folder.Url + "/" + $file.Name, [System.IO.Stream]$fileStream, $true)
    write-host "Success"

    #Close file stream
    $fileStream.Close();
}

#Dispose web

$web.Dispose()

Note:-

    http://abcd:12312/sites/Sample = site collection url

Monday, 5 August 2013

sharepoint 2010 disable i like it tags and notes

1.open "Central Administration" and choose the "System settings"
2.click the "Manage Farm Features"
3. then find the "Social Tags and Note Board Ribbon Controls"
4.click the DeActivate and then Click the "DeActivate this Features"

the document could not be opened for editing. a windows sharepoint services compatible application

solution:-
            am using Mozila FireFox latest version  its works for me

Enable/Disable Delete Option of List in Sharepoint 2010 using Powershell

Script:-

If ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{
Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell
}

$web = Get-SPWeb -Identity "http://ABCD:12312/sites/Sample/" -AssignmentCollection $assignment
$list = $web.lists["TestList1"]
$list.AllowDeletion = $false
$list.Update()


Note:-

 http://ABCD:12312/sites/Sample/ = site collection url
TestList1 = List Name

Sunday, 4 August 2013

programmatically upload file to document library in sharepoint 2010



Code:-

using (SPSite site = new SPSite(SPContext.Current.Site.ID))
  {

using (SPWeb web = site.OpenWeb())
  {

SPSecurity.RunWithElevatedPrivileges(delegate()
               {

SPDocumentLibrary documentLib = web.Lists["Shared Documents"] as SPDocumentLibrary;

Stream fStream = FileUpload1.PostedFile.InputStream;
byte[]  _byteArray = new byte[fStream.Length];
fStream.Read(_byteArray, 0, (int)fStream.Length);
fStream.Close();

web.AllowUnsafeUpdates = true;

string _fileUrl = documentLib.RootFolder.Url + "/" + FileUpload1.PostedFile.FileName;

bool IsOverwriteFile = true;
SPFile file = documentLib.RootFolder.Files.Add(_fileUrl, _byteArray, IsOverwriteFile);

SPListItem item = file.Item;
item["Title"] = FileUpload1.PostedFile.FileName;
item.Update();
file.Update();

web.AllowUnsafeUpdates = false;
             
      });          
 }
     
 }

Thursday, 1 August 2013

Reterive a list of checkout file in sharepoint 2010 site collection using powershell

Script:-

$webAppURL = "Enter your Web application Url"

function ReportCheckedOutItems() {
    $webapp = Get-SPWebApplication $webAppURL

    foreach ($site in $webapp.Sites)
    {
        write-host "Site Collection: $($site.Url)"
        $allwebs = $site.allwebs
        foreach($web in $allwebs)
        {
            $count = 0
            write-host "--Site: $($web.Url)"
            foreach ($list in ($web.Lists | ? {$_ -is [Microsoft.SharePoint.SPDocumentLibrary]})) {
                Write-Host "-----List: $($list.RootFolder.ServerRelativeUrl)..."
                foreach ($item in $list.CheckedOutFiles)
                {
                    if (!$item.Url.EndsWith(".aspx"))
                    {
                        continue
                    }
                    write-host "File: $($item.Url) - checked out by $($item.CheckedOutBy)" -ForeGroundColor Red
                    $count++
                }
                foreach ($item in $list.Items)
                {
                    if ($item.File.CheckOutStatus -ne "None")
                    {
                        if (($list.CheckedOutFiles | where {$_.ListItemId -eq $item.ID}) -ne $null)
                        {
                            continue
                        }
                        write-host "File: $($item.Url) - checked out by $($item.CheckedOutBy)" -ForeGroundColor Red
                        $count++
                    }
                }
            }
            if ($count -gt 0)
            {
                write-host "Found $count checked out files for site $web" -ForeGroundColor Red
            }
        }
    }
}

ReportCheckedOutItems