Saturday, 16 April 2016

On Export to Excel having problem on second Click

client side in HTML Tag add

OnClientClick="_spFormOnSubmitCalled = false;_spSuppressFormOnSubmitWrapper=true;"


Example


<asp:Button ID="btnExportToExcel" runat="server" Text="Export to Excel" onclick="btnExportToExcel_Click" OnClientClick="_spFormOnSubmitCalled = false;_spSuppressFormOnSubmitWrapper=true;" />

Monday, 14 March 2016

Access on ContentBD for deployment using PoweShell


1. Open PowerShell window "Run as Administrator"
2. put in below script desired SiteCollectionName and UserName whom need to grant permission.



$contentdb = Get-SPContentDatabase -Site http://serverName/sites/siteName
Add-SPShellAdmin -UserName 'domainName\userloginid' -database $contentdb

Thursday, 10 March 2016

Web services/WCF binding on Client Machine




Step 1. Accessing Web services with impersonation Credential 

          1. Add Service reference in Project.
          2. Add Service NameSpace
                     using MyNameSpace.MyNameSpacee;
                         MyNameSpacee.MyWebServiceSoapClient myNameSpacee = new MyWebServiceSoapClient();





Step 2. change the binding in web.config/App.Config like below...



<system.serviceModel>
        <bindings>
            <basicHttpBinding>
              <binding name="MyWebServiceSoap">
                <security mode="TransportCredentialOnly">
                  <transport clientCredentialType="Ntlm" proxyCredentialType="None" realm=""/>
                  <message clientCredentialType="UserName" algorithmSuite="Default"/>
                </security>
              </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address=""
                binding="basicHttpBinding" bindingConfiguration="MyWebServiceSoap"
                contract="MyNameSpace.MyWebServiceSoap" name="MyWebServiceSoap" />
        </client>
    </system.serviceModel>

          3. Add Dynamically Address for current Web

  myNameSpacee.Endpoint.Address = new System.ServiceModel.EndpointAddress(SPContext.Current.Web.Url+"/_layouts/15/MyWebServices/MyWebService.asmx");

OR

Add Static Services Address in

Web.config/App.config like below inside Client Tag

 <client>
            <endpoint address="http://site:port/_layouts/15/MyWebServices/MyWebService.asmx""
                binding="basicHttpBinding" bindingConfiguration="MyWebServiceSoap"
                contract="MyNameSpace.MyWebServiceSoap" name="MyWebServiceSoap" />
        </client>



            myNameSpacee.ChannelFactory.Credentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
            myNameSpacee.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;



4. finally Call your WebMethod 


myNameSpacee.GetMYMethod();










OutLook Add-In VSTOInstaller.exe.config error while installing Add-in

Error like below 


The value of the property 'type' cannot be parsed. The error is: Could not load file or assembly 'Microsoft.Office.BusinessApplications.Fba, Version=14.0.0.0, Culture=neutral, PublicKeyToken=XXXXXXXXX' or one of its dependancies. The system cannot find the file specified. (C:\Program Files (x86)\Common Files\Microsoft Shared\VSTO\10.0\VSTOInstaller.exe.Config line 10)

or

The value of the property 'type' cannot be parsed. The error is: Could not load file or assembly 'Microsoft.Office.BusinessApplications.Fba, Version=14.0.0.0, Culture=neutral, PublicKeyToken=XXXXXXXXX' or one of its dependancies. The system cannot find the file specified. (C:\Program Files\Common Files\Microsoft Shared\VSTO\10.0\VSTOInstaller.exe.Config line 10)


Solution




  • Open Windows Explorer
  • Open the folder C:\Program Files (x86)\Common Files\Microsoft Shared\VSTO\10.0
  • If that folder does not exist, try C:\Program Files\Common Files\Microsoft Shared\VSTO\10.0
  • Rename the file VSTOInstaller.exe to VSTOInstaller.exe.Config

Tuesday, 8 March 2016

GroupBy With LinQ

  var mainQuery = finaldocCount.GroupBy(u => new { u.ProjectCode })
                                                                      .Select(grp => new
                                                                      {

                                                                          ProjectCode = grp.Key.ProjectCode,
                                                                          mailList = grp.ToList()
                                                                      }).ToList();


                          foreach (var item in mainQuery)
                                {
                                    foreach (finalNameCount v in item.mailList)
                                    {

                                        v.Name;


                                   
                                    }
                                }

Wednesday, 24 February 2016

Retrive Allfiles from document library and subfolder with metadatacolumns

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;

using Microsoft.Office.InfoPath;

using System.IO;
using System.Xml;
using System.Xml.XPath;

using System.Collections;
using System.Data;
using System.Data.Common;


using System.Security.Principal;
using Microsoft.SharePoint.Utilities;
namespace DeleteAllitem
{
    class Program
    {
        static List<DocumentName> doclist = new List<DocumentName>();
        static void Main(string[] args)
        {
            using (SPSite site = new SPSite("http://win-0c3p6kepvck:100/kkk/"))
            {
                site.AllowUnsafeUpdates = true;
                using (SPWeb web = site.OpenWeb())
                {
               
                    web.AllowUnsafeUpdates = true;
                    SPDocumentLibrary list =(SPDocumentLibrary)web.Lists["JS"];
                    SPListItemCollection  itemcoll = list.Items;
                    foreach (SPListItem  item in itemcoll)
                    {

                     
                        DocumentName d = new DocumentName
                        {
                           Name1= Convert.ToString(item["Name"]),
                           Title1=Convert.ToString(item["Title"]),
                           FileUrl=item.File.ServerRelativeUrl,
                           Department=Convert.ToString(item["Department"])
                        };
                        doclist.Add(d);
                 
                    }
                    Console.WriteLine("Please Enter FileName....");
                    string s=Console.ReadLine();
                    Console.WriteLine("Please Enter Department....");
                    string departmentt=Console.ReadLine();
                    var fileName=doclist.Where(w=>w.Name1.Contains(s) && w.Department==departmentt);
                    foreach (var c in fileName)
                    {

                        Console.WriteLine(c.Name1);
                        Console.WriteLine(c.FileUrl);
                    }
                    Console.WriteLine("end....");
                    Console.Read();




                    web.AllowUnsafeUpdates = false;
                 
                }
                site.AllowUnsafeUpdates = false;
            }
        }
        public class DocumentName
        {

            private string Name;

            public string Name1
            {
                get { return Name; }
                set { Name = value; }
            }
            private string Title;

            public string Title1
            {
                get { return Title; }
                set { Title = value; }
            }
            private string fileUrl;



            public string FileUrl
            {
                get { return fileUrl; }
                set { fileUrl = value; }
            }
            private string department;

            public string Department
            {
                get { return department; }
                set { department = value; }
            }
        }
     
         
           


    }
}

Sunday, 21 February 2016

Copy List Item Source List to Destination List

public void CopyList(SPList src)
{
    //Copy items from source List to Destination List
    foreach (SPListItem item in src.Items)
    {
        if(isUnique(item.UniqueId))
        {
          newDestItem = DestinationList.Items.Add();

          foreach (SPField field in src.Fields)
          {
             try
              {
                if ((!field.ReadOnlyField) && (field.InternalName!="Attachments"))
                  newDestItem[field.InternalName] = item[field.InternalName];
               }
             catch (Exception ex)
              {
              //you should save the "ex" somewhere to see its outputs
               ex.ToString();
              }
           }
           newDestItem.Update();  //only now you call update!
        }
       }
      } 

Delete attached Event reciver from list

Add-PSSnapin Microsoft.SharePoint.PowerShell –erroraction SilentlyContinue

$web = Get-SPWeb -Identity http://siteURL/
$list = $web.GetList($web.Url + "/Lists/" + "ListName")

$type = "ItemDeleting"

$numberOfEventReceivers = $list.EventReceivers.Count

if ($numberOfEventReceivers -gt 0)
{
   for( $index = $numberOfEventReceivers -1; $index -gt -1; $index–-)
   {
      $receiver = $list.EventReceivers[$index] ;
      $name = $receiver.Name
      $typ = $receiver.Type ;

      if($name -eq "EventReceiver1ItemDeleting")
      {
         $receiver.Delete()
         Write-Host "Event receiver " $name " is deleted"
      }
   }
}
else
{
   Write-Host " There is no EventReceivers of type " $type " registered for this list "
}

$web.Dispose()

Get Attached Event Reciver to List/Library

$spWeb = Get-SPWeb http://siteUrl/ ;
$spList = $spWeb.Lists["LisName"];
$spList.EventReceivers | Select Name, Assembly, Type;

Delete Hidden Feature

$feature = Get-SPFeature | ? { $_.DisplayName -eq "FeatureName_Feature1" }
 $feature.Delete()